How to add and remove a flag for a post in a plugin


Yes, you can! Following Reverse engineer the Discourse API, you can figure out how to do it.

In your case, it’s a POST request to /post_actions, with the following possible payload:

field descritpion
id The post ID
post_action_type_id The post action type ID
message Message used with notify_user and notify_moderators actions types
is_warning Whether you flag a topic
take_action Whether to agree with the flag and hide the post immediately
queue_for_review Whether to queue immediately for review
flag_topic Whether you flag a topic
action type ID
off_topic 3
inappropriate 4
spam 6
notify_user 7
notify_moderators 8

To delete a flag, you can send a DELETE request to /post_actions/<post_id> and as payload, post_action_type_id.

Hope that helps! :+1: