The discussion revolves around retrieving a list of users who liked a post using the Discourse API. pontus.dualdecade initially asks how to find out which users liked a post, given that the actions_summary only shows the total number of likes and whether the current user has liked the post.
Falco provides a solution using the post_action_users endpoint, but the link is broken. pontus.dualdecade corrects the link and provides an example of the correct API call: GET /post_action_users?id=13&post_action_type_id=2.
This call returns a list of users who liked the post with the specified ID. Falco notes that the Accept header is required to receive the response in JSON format.
Later, paigen11 asks for help with a similar issue on their company’s Discourse forum. They are unable to retrieve the list of users who liked a post, despite using the correct API call. leonardo explains that the issue is due to the post being a special type of post that cannot be interacted with, and provides an alternative post ID that has likes. paigen11 thanks leonardo for the help.
Additionally, paigen11 asks if there is a webhook that can be set up to notify when a user likes a post, but no solution is provided.
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.
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.
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.
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.
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: