Get number of likes for a single post?

AI-generated summary

In a discussion titled “Get number of likes for a single post?” under the Dev category and tagged with rest-api, mr8 initially sought a way to retrieve the like count for an individual post via the Discourse API, noting that like_count only appeared for entire topics. After some exploration, mr8 discovered the like count is available under the actions_summary field in the API response — for example, {"id":2, "count":5,"acted":true} — though this field is omitted if a post has no likes. smileBeda pointed out this behavior makes the API unreliable and noted the absence of documentation for this feature in official API docs. blake acknowledged the gap and committed to improving the API documentation, explaining it’s partially auto-generated via rspec tests using rswag. smileBeda offered to help with documentation, asking whether it’s manually written or code-generated; blake clarified it’s a hybrid approach, and shared a link to a meta topic explaining how to contribute to the API docs.

Hello,
I’m trying to get the number of likes for a single post via the API, but can’t seem to find it…

I see a like_count for the entire topic, but can’t seem to find the individual like count for each post in either /t/123.json or /posts/222.json.

I noticed that I can get a list of users who liked a post via /post_action_users.json and add them up manually, but what is the recommended way to to get the “like count” for an individual post?

Thanks!

I’m an idiot!
Found it under "actions_summary":

{"id":2,"count":5,"acted":true}

Well, hope this helps someone else!

Love you man! that helps me a lot!

Unfortunately Discourse removes that property if the post has no likes
Also it is not in the API doc: Discourse API Docs, Discourse API Docs

Thus, unreliable and code gets polluted by unnecessary “if property object exist”
Should be improved, at best.

Thank you for the feedback. Ya, looking at the api docs there isn’t any info on fetching likes, just on creating them. I’ll start with improving the api docs in that department.

Definitely love you for that.
If I can help with this (is it human written?!) let me know
But I suspect you use something like PHPdoc, just for Ruby or whatever it is that Discourse is written in?
I have no experience in that language so if it is programmatic I cannot help with it (yet) :stuck_out_tongue:

I’d say it’s 50/50. There is still manual work, but they are generated from rspec tests using a tool called rswag.