Get number of likes for a single post?

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!

2 Likes

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

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

Well, hope this helps someone else!

16 Likes

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.

1 Like

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.

1 Like

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:

1 Like

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

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.