Getting who liked a post from the API

So, when we get a post like so:

GET /posts/13.json

We can see in the json actions_summary which contains the number of likes the post has. And you can deduce if the user I am logged in as has liked if “acted” or “can_act” is present.

"actions_summary": [
          {
            "id": 2,
            "count": 2,
            "acted": true
          },

But, how do I lookup which users liked the post? We have 2 likes here, one is mine since “acted” is true. But there is one other like. How do I find out which user that is through the API? It is fine if we have to use an admin account to check.

3 Likes

As explained at How to reverse engineer the Discourse API

curl 'https://meta.discourse.org/post_action_users?id=507029&post_action_type_id=2'
3 Likes

Your link does not work.

This works for me though:

GET /post_action_users?id=13&post_action_type_id=2

This outputs

{
  "post_action_users": [
    {
      "id": 1,
      "username": "ausername",
      "name": null,
      "avatar_template": "/letter_avatar_proxy/v2/letter/i/{size}.png",
      "post_url": null,
      "username_lower": "ausername"
    },
    {
      "id": 10,
      "username": "anotherusername",
      "name": null,
      "avatar_template": "/letter_avatar_proxy/v2/letter/{size}.png",
      "post_url": null,
      "username_lower": "anotherusername"
    }
  ]
}

Which is a list of users who liked the post with id 13

It was missing the accept header:

curl 'https://meta.discourse.org/post_action_users?id=507033&post_action_type_id=2' -H 'Accept: application/json'
3 Likes

you need to pass

/post_action_users.json?id=507033&post_action_type_id=2

Hello!

I’m trying to ascertain a similar thing for a Discourse forum my company uses: https://discuss.blues.io

I have staff level credentials, however, when I look at the JSON payload for posts that have been liked, I don’t see any indication of it either in the actions_summary or the post_action_users JSON payloads.

For example, this post has lots of replies and likes, but when I query it in the browser https://discuss.blues.io/post_action_users.json?id=31&post_action_type_id=2, I get back {"post_action_users":[]}

Perhaps the API has changed? Or I’m querying for the wrong thing. Any help is greatly appreciated.

And a follow up question: is there a webhook I could potentially set up to be notified when a user likes a post identifying the user and the post? We’d like to capture this info for analytics purposes.

Thanks!

1 Like

hello Paige!

The post with ID 31 is a small post action for pinning the topic globally (ie. Post.find(31).action_code == 'pinned_globally.enabled'), and those posts can’t be interacted with like normal posts, so there’s no way it can have likes.

There is only one regular post in that topic, but it does not have any likes either.

Try Post 33 - that one does have likes and you can see them serialized here:

https://discuss.blues.io/post_action_users.json?id=33&post_action_type_id=2

5 Likes

Hi Leonardo,

Thanks very much for the info about different types of posts - that’s great info to know.

I appreciate the response.

Cheers,
Paige

2 Likes