Forum Discussion

ldelagoutte's avatar
4 years ago

Subscribers to label

by using restapi/vc/boards/id/<id>/labels/labels, I get the list of labels related to a board.

fine.

But how can I get the list of subscribers to these labels ?

I mean I don"t have a list of users to go trough and say yes or no this user is a subscriber, I want to get the list from these labels list.

I browsed the documentation from one end to the other, but did not manage to find a solution 😞

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)

    ldelagoutte jeffshurtliff Akenefick I heard back from Engineering. This is indeed a gap in the API. The issue has come up in the past, yet a formal ticket for a feature request never came as a result. 

    I think the best path moving forward is to file a ticket through Support. Bugs/Enhancements/Feature requests have more sway when they come from customers than only from within. Be sure to mention the both the inability to get subscribers to a label as well as the need to interact with subscriptions not limited to the user account making the request.

     

  • jeffshurtliff and ldelagoutte  I tried the nested subscriptions and it worked, but it gave me both label and conversation subscriptions.

    SELECT id, target.type, subscriber, href FROM subscriptions WHERE target.id = 'aktestboard' AND target.type = 'board' AND include_nested = true

     

    I tried to constrain it to just labels with nested_target_type but could not get that to work.

    • ldelagoutte's avatar
      ldelagoutte
      Guide

      Sorry but it doesn't work : when I tried your query , it only returned my subscriptions 😞

      As I mentioned, I want to get all subscribers, not only myself

      I am normally admin, so there should not be any issue with rights.

       

       

  • Very odd, I just confirmed the same thing.  It seems that the nested_target_type only works for the board and category values and not for conversationlabel or message and possibly others.

    I also tried filtering for a specific label ID and struck out as well:

    Query:

     

    SELECT * FROM subscriptions WHERE target.id = 'Downloads' AND target.type = 'label'

     

    Response:

     

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

     

     

    SuzieH, are you and the Engineering Team already aware of this limitation?  Any suggestions for filtering only for label subscriptions another way with LiQL?

    Akenefick, where are you using the LiQL response, is it in some FreeMarker code or through a script or something?  I ask because you could always filter the query results after the fact...although I could see where this would almost certainly result in much larger query results than you'd want.

    FreeMarker Example:

     

    <#-- Import dependencies -->
    <#import 'theme-lib.common-functions' as commonUtils />
    
    <#-- Perform the LiQL query -->
    <#assign query = "SELECT subscriber,target FROM subscriptions WHERE target.id = 'my-awesome-forum' AND target.type = 'board' AND include_nested = true" />
    <#assign subscriptions = commonUtils.executeLiQLQuery(query, false, true)![] />
    
    <#-- Initialize a sequence to store the results -->
    <#assign labelSubscriptions = [] />
    
    <#-- Loop through the data -->
    <#list subscriptions as subscription>
      <#if subscription.target.type == 'label'>
        <#assign subData = {
          "label": (subscription.target.id)!"UNKNOWN_LABEL", 
          "user": (subscription.subscriber.login)!"UNKNOWN_LOGIN"
        } />
        <#assign labelSubscriptions += [subData] />
      </#if>
    </#list>

     

    (Disclaimer: I wrote the code above from memory without testing so it should be correct and free from syntax errors.  🙂

    EDIT: Adjusted the executeLiQLQuery function call to run as admin per your latest comment. 

    • Akenefick's avatar
      Akenefick
      Genius

      Hi jeffshurtliff  it was actually ldelagoutte that originally asked about this, and he discovered an even larger problem. This only returns your subscriptions (the logged in user). So it appears it's not intended to be used this way at all.

      • jeffshurtliff's avatar
        jeffshurtliff
        Boss

        Akenefick ah yep, I just confirmed this by switching users (to another admin user), subscribing to a label, and running the LiQL query in the API browser and, sure enough, it only returned that user's subscription and nothing from my user.  Major bummer.

    • SuzieH's avatar
      SuzieH
      Khoros Alumni (Retired)

      Hi jeffshurtliff.  I haven't dug into the use case and subsequent limitation. I'm passing this on to Engineering/Product Management.