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

**URL:** https://meta.discourse.org/t/how-to-add-and-remove-a-flag-for-a-post-in-a-plugin/293630
**Category:** Development
**Created:** [January 31, 2024, 1:22pm UTC](https://meta.discourse.org/t/how-to-add-and-remove-a-flag-for-a-post-in-a-plugin/293630 "2024-01-31T13:22:14Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [January 31, 2024, 5:32pm UTC](https://meta.discourse.org/t/how-to-add-and-remove-a-flag-for-a-post-in-a-plugin/293630/2 "2024-01-31T17:32:57Z")

</div>

Hi,

Yes, you can! Following [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576), 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! 👍

---

_[View the full topic](https://meta.discourse.org/t/how-to-add-and-remove-a-flag-for-a-post-in-a-plugin/293630)._
