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!

Ich liebe dich, Mann! Das hilft mir sehr!

Leider entfernt Discourse diese Eigenschaft, wenn der Beitrag keine Likes hat.
Außerdem ist sie nicht in der API-Dokumentation aufgeführt: Discourse API Docs, Discourse API Docs

Daher unzuverlässig und der Code wird durch unnötige „if property object exist“-Prüfungen verschmutzt.
Sollte im besten Fall verbessert werden.

Vielen Dank für Ihr Feedback. Ja, wenn ich mir die API-Dokumentation ansehe, gibt es keine Informationen zum Abrufen von Likes, nur zum Erstellen. Ich werde zunächst die API-Dokumentation in diesem Bereich verbessern.

Das liebe ich definitiv an dir.
Wenn ich dabei helfen kann (ist das von Menschen geschrieben?!) lass es mich wissen.
Aber ich vermute, du verwendest so etwas wie PHPdoc, nur für Ruby oder was auch immer Discourse in geschrieben ist?
Ich habe keine Erfahrung in dieser Sprache, also wenn es programmatisch ist, kann ich (noch) nicht damit helfen :stuck_out_tongue:

Ich würde sagen, es ist 50/50. Es gibt immer noch manuelle Arbeit, aber sie werden aus rspec-Tests mit einem Tool namens rswag generiert.