Forum Discussion

Inactive User's avatar
Inactive User
5 years ago

How to subscribe to a label using a custom link, expecially in a Forum?

Is there a way to subscribe to a label using a custom link? I see that in the Subscribe to Label link in TKBs, there is a url and a token. (See code below)

Is there a way to do this without the token? Or how does one generate a token?

I have a custom listing page I want to use, and want to add a subscribe to label link on it...

 

<a class="lia-link-navigation subscribe-to-label-link lia-link-ticket-post-action" data-lia-action-token="q-rlUVWyJprfXFSJi-OCeZNSAFKk7xQH-6zDhiPg3sI." rel="nofollow" id="link_7" href="https://yoursite.com/t5/tkb/v2/page.filteredbylabelname.subscribetolabelname.link:subscribeaction/label-name/Analytical%20Application%20Development/board-id/add-ins/subscribed/false?t:ac=blog-id/add-ins/label-name/analytical%20application%20development">Subscribe</a>

 

  • Hi Inactive User ,

    You can look to use the subscriptions API over here to subscribe/unsubscribe a user to a label:

    https://developer.khoros.com/khoroscommunitydevdocs/docs/create-user-subscriptions#section-label-subscription

    curl -X POST \
        https://[COMMUNITY DOMAIN]/api/2.0/subscriptions \
        -H 'content-type: application/json' \
        -H 'li-api-session-key: [SESSION KEY]' \
        -d '{
        "data":{
            "type":"subscription",
            "target":{
                "type":"label",
                "id":"Mexico"
            },
            "board":{
                "id":"vacationBlog"
            }        
        }
    }'

    Please Give Kudos if you find this post useful and also mark this as Accepted Solution if this is the required solution.

    Regards

    Tarun Kumar

  • Hi Inactive User ,

    Yes, this should work in the endpoints., i.e. you can call a custom endpoint on link click, or you can also look to create a complete ajax call with jquery(convert the curl command to javascript code) if you are not comfortable with Freemarker. But the use of the freemarker object is good as it will not expose the API and Data.

    Documentation to use Jquery in the community

    https://developer.khoros.com/khoroscommunitydevdocs/reference/liaaddscript

     

    Please Give Kudos if you find this post useful and also mark this as Accepted Solution if this is the required solution.

    Regards

    Tarun Kumar

    • Inactive User's avatar
      Inactive User

      I'm very confused here; trying to do it in FM but the feedback is so limited. How can I know the structure of the call response (resp) so I can work with what's returned? I try it as a list and get nothing I recognize, plus errors. Also, how do I generate A session key?

       

      <#assign messagePostCall = restBuilder()
         .method("POST")
         .path("/subscriptions")
         .body({
                  "type": "message",
                  "board": {
                   
                      "id": "angular-test"
                  },
                  "target": { 
                      "type":"label",
                      "id": "Jupiter"
                           }
              })
         .admin(true) />
      <#assign resp = messagePostCall.call() />
      
      
      <#list resp as k ,v>
      k: ${k}
      </#list>

       

       

      This is what I get from that <#list>. Looks like a list of properties but nothing I can use, until we get to an error. 

       k: getClass k: validTemplateModelObject k: toSerializedString k: isValidTemplateModelObject k: hashCode k: equals k: get k: toString

      FreeMarker template error (HTML_DEBUG mode; use RETHROW in production!)
      Attempt to use a type that is not allowed: java.lang.Class
    • Inactive User's avatar
      Inactive User

      Tarun, can you give me an example of the API call in JQuery?

      • Tarun's avatar
        Tarun
        Maven

        Hi Inactive User ,

        you can try the following code in a component:

        <@liaAddScript>
        ;(function($){
        $.ajax({
        type: "Get",
        url: "/api/2.0/search?q=SELECT * FROM users",

        success: function(data) {
        console.log(data)

        },
        });
        })(LITHIUM.jQuery);
        </@liaAddScript>

        Please Give Kudos if you find this post useful and also mark this as Accepted Solution if this is the required solution.

        Regards

        Tarun Kumar

         

  • Hi Inactive User ,

    the API Would Goi in the URL for the Ajax call.You need to pass data as json to the ajax call.

    The success message would look something like:

    data:
    
    href: "/nodes/board:board-id"
    
    id: "board-id"
    
    type: "node"
    
    __proto__: Object
    
    href: "/users/id"
    
    id: "id"
    
    login: "login"
    
    type: "user"
    
    view_href: "*****"
    
    __proto__: Object
    
    href: "/labels/88"
    
    id: "88"
    
    type: "label"
    
    href: "/labels/88/subscriptions/2121"
    
    id: "2121"
    
    node:
    
    subscriber:
    
    target:

     

    Please Give Kudos if you find this post useful and also mark this as Accepted Solution if this is the required solution.

    Regards

    Tarun Kumar