Forum Discussion

Akenefick's avatar
Akenefick
Genius
3 years ago

Create A Kudo With API

I would like to give a kudo to a message from a specified user. I don't think API V1 will work. /restapi/vc/messages/id/[id]/kudos/give doesn't allow me to specify a user.

I tried to create a kudo with an API v2 Post call as shown here The Community API v2 request (khoros.com) (see below) but received an error message that the resource wasn't found. Am I doing something wrong or is this not supported for kudos? If not is there a way to do what I want with API v1? Thanks.

 

{
    "data": {
        "type": "kudo",
        "user": {
            "id": "378002"
        },
        "message": {
            "id": "567232"
        }
    }
}

 

 

  • MattV's avatar
    MattV
    Khoros Staff

    SuzieH is basically correct; you'd have to "switch" to that user, and use the session key to kudo that message. You could still use APIv1 at that point too since you'd have the session key. But you'd have to guard the session key with your life while you're using it, and then discard it with 

    /authentication/sessions/logout
     
    as soon as you're done.
     
    Note; this can't be done in freemarker, since freemarker *always* runs as the currently logged in user, even if you try to pass in the session keys to the api calls.
     
    There is one sort-of workaround, in that if you pass a valid session key to an endpoint, the rest calls in that endpoint will run as the user that belongs to that session key.
     
    But you can't call endpoints in freemarker either, so it's of limited use 🙂
    • SuzieH's avatar
      SuzieH
      Khoros Alumni (Retired)

      Thank you so much for that clarification! I'll update our dev docs with the caveat/warning you mentioned here

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)

    Hi Akenefick 

    I'm wondering if you can kudo a message on behalf of another user similar to the way you would create a subscription on behalf of a user. After you've generated the session key for the user, you could use /api/2.0/messages/{message-id}/kudos

    .Here's the doc for that endpoint: Kudo message

    Let me know if this gives you what you need.

  • SuzieH MattV  Thank you both this is very helpful. I had a couple of questions. 

    First, this could be done with JavaScript then? And if so is it possible to generate a session key like this for a user with an SSO account or would that complicate things? Also, if I understand this correctly, you wouldn't actually be switching user just generating the session key for the user while you remain logged in? So if I had a list of users I could loop through them kudoing with each one in turn.

    Thanks