Determining if the authenticated API user has liked the post in the getTopic API response

I’ve been working on a Wordpress commenting plugin for the last week and have had great success connecting to, creating posts and updating data via the Discourse API and my fork of the discourse-php-API plugin - Work through the createPost request to get it working by benbowler · Pull Request #14 · discoursehosting/discourse-api-php · GitHub

Looking at the /posts response I can see the actions summary response for each post and get the total count of likes.

actions_summary: Array(6)
0: {id: 2, count: 1, can_act: true}
1: {id: 3, can_act: true}
2: {id: 4, can_act: true}
3: {id: 8, can_act: true}
4: {id: 6, can_act: true}
5: {id: 7, can_act: true}
length: 6
__proto__: Array(0)

But can_act is true regardless of whether the user has liked the post or not. How do you show the correctly?

If the user you’re using with the API (Api-Username) has liked a post, you should see acted: true

Hmm, let me take a look.

I’ve got it. The plugin wasn’t requesting based on the passed user. I’ll update the library to help anyone in future.

2 Likes