Forum Discussion

rajjay's avatar
rajjay
Adept
6 months ago

subscriptions count at article level

Hello,

I am attempting to retrieve subscriptions count  at the article level using the following SQL query:

 

SELECT * FROM subscriptions WHERE target_type = 'article' AND target_id = '8223';

 

Although the response indicates success, I'm not receiving any subscription lists. Could someone please review the query and provide guidance on what might be incorrect?

I subscribed the article even after it just returning nothing

 

PageType : TkbArticlePage
response 
{
"status" : "success",
"message" : "",
"http_code" : 200,
"data" : {
"type" : "subscriptions",
"list_item_type" : "subscription",
"size" : 0,
"items" : [ ]
},
"metadata" : { }

Thank you in advance for your assistance.

 

  • As far as I'm aware the v2 API subscriptions are internally scoped to the currently authenticated user, which is not very helpful if you want to get subscriptions for anything else but the current or another specific user. I think there might be a way with API v1, but I have to dig in some dusty code, will get back to you if I find it!

    The API v1 call I had in mind was this (docs here)

    /restapi/v1/<boards|blogs|groups>/id/<board|blog|group.id>/subscribers/email/board/count?page_size=1000&restapi.response_format=json

    checked the v1 API reference again to see if we can get subscribers for a specific thread/article because I couldn't get it to work playing around with the calls, but it doesn't seem like there is such a query...

    also checked if I could construct a similar query for categories (because there are category subscriptions), but it doesn't work either...

    EDIT: I knew there was something else, but it's a bit more cryptic...

    So technically for what you are specifically asking you can do this:

    /restapi/v1/threads/id/<thread.id>/subscriptions/global/type/email?page_size=1000&restapi.response_format=json

    problem is, there is no /count, at least I get an error if i do this:

    /restapi/v1/threads/id/<thread.id>/subscriptions/global/type/email/count?page_size=1000&restapi.response_format=json

    so you'd have to basically page through potentially 1000's of user objects just to get a count, which is not ideal to put it nicely...

    for categories (and other nodes I assume, didn't do deep testing), the /count seems to work though with a similar query path:

    /restapi/v1/categories/id/<category.id>/subscriptions/global/email/category/count?page_size=100&restapi.response_format=json

    there might also be some obscure way to get label subscriptions with something like:

    /restapi/v1/subscriptions/global/email/textLabel?page_size=100&restapi.response_format=json

    although I have no example community to play around with where that would be used afaik. The question would be how to scope that call to a specific label text, which I couldn't get to not throw an error... Technically I guess something like this would work for all labels in a specific board:

    /restapi/v1/boards/id/<board.id>/subscriptions/global/email/textLabel?page_size=100&restapi.response_format=json

    but I can't confirm...

    See related docs here and here