# Post Destroyed Webhook Event

**URL:** https://meta.discourse.org/t/post-destroyed-webhook-event/110259
**Category:** Support
**Created:** [February 27, 2019, 5:40pm UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259 "2019-02-27T17:40:01Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![thisnthat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thisnthat/32/164804_2.png) [@thisnthat](https://meta.discourse.org/u/thisnthat)
#### Post date: [February 27, 2019, 5:40pm UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/1 "2019-02-27T17:40:01Z")

</div>

I am currently using [v2.3.0.beta2 +46](https://github.com/discourse/discourse/compare/86fe423f5eb8aa0eb8534d06eeb5848678630412...tests-passed)

I have a webhook setup for post events. The only event I do not appear to see is post\_destroyed. I have testing deleting and restoring multiple posts and I see every post\_recovered event, but I do not see any events for the post being deleted.

To reproduce, create a webhook and enable post events. Delete a post on a topic that would trigger that webhook and see no delete event created.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 28, 2019, 6:04am UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/2 "2019-02-28T06:04:18Z")

</div>

Can you repro this @vinothkannans?

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [February 28, 2019, 6:34am UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/4 "2019-02-28T06:34:18Z")

</div>

No, this is working fine for me in latest version. I’m able to see triggered `post_destroyed` events in URL `/admin/api/web_hooks/1/events`. @thisnthat did you checked the events list page?

---

<div class="post-metadata">

### Author: ![thisnthat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thisnthat/32/164804_2.png) [@thisnthat](https://meta.discourse.org/u/thisnthat)
#### Post date: [February 28, 2019, 5:14pm UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/5 "2019-02-28T17:14:40Z")

</div>

I have, this is the process I used to test it with a snippet of the header and payload of each event

I created the post

Header

```plaintext
User-Agent: Discourse/2.3.0.beta2
X-Discourse-Event-Id: 90
X-Discourse-Event-Type: post
X-Discourse-Event: post_created

```

Payload

```plaintext
{
  "post": {
    "id": 44144,
    ...
    "deleted_at": null,

```

I deleted the post and no event was triggered

I restored the post

Header

```plaintext
User-Agent: Discourse/2.3.0.beta2
X-Discourse-Event-Id: 91
X-Discourse-Event-Type: post
X-Discourse-Event: post_recovered

```

Payload

```plaintext
{
  "post": {
    "id": 44144,
    ...
    "deleted_at": null,

```

I deleted it again – No event

I edited the post

Header

```plaintext
User-Agent: Discourse/2.3.0.beta2
X-Discourse-Event-Id: 92
X-Discourse-Event-Type: post
X-Discourse-Event: post_edited

```

Payload

```plaintext
{
  "post": {
    "id": 44144,
    ....
    "deleted_at": "2019-02-28T17:07:28.427Z",

```

I restored the post

Header

```plaintext
User-Agent: Discourse/2.3.0.beta2
X-Discourse-Event-Id: 93
X-Discourse-Event-Type: post
X-Discourse-Event: post_recovered

```

Payload

```plaintext
{
  "post": {
    "id": 44144,
    ...
    "deleted_at": null,

```

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [March 1, 2019, 4:39am UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/6 "2019-03-01T04:39:33Z")

</div>

I will recommend you to look at the URL `/admin/api/web_hooks/WEBHOOK_ID/events` for more info. If a triggered webhook event is failed then it will have the details. Also look at the `/logs` at the time of `post_destroyed` event. If you provide more details about the fail it will help me to debug the issue.

---

<div class="post-metadata">

### Author: ![thisnthat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thisnthat/32/164804_2.png) [@thisnthat](https://meta.discourse.org/u/thisnthat)
#### Post date: [March 1, 2019, 1:55pm UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/7 "2019-03-01T13:55:56Z")

</div>

I have reviewed /admin/api/web\_hooks/WEBHOOK\_ID/events and the details of the events are in my previous post. Event id 90 was apost\_ create, 91 post\_recovered, 92 post\_edited, 93 post recovered.

I tested again this morning. I reviewed the logs rails/production.log, rails/production\_errors.log, rails/unicorn.stderr.log, rails/unicorn.stdout.log,

This is a snippet from the access logs for the previously mentioned events

```plaintext
[28/Feb/2019:17:04:50 +0000] "POST /posts HTTP/2.0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "posts/create" 200 1517 "***/t/testing-discord-bot/10137/17" 1.268 1.268 "Thisnthat"
[28/Feb/2019:17:04:55 +0000] "PUT /posts/44144/recover HTTP/2.0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "posts/recover" 200 1516 "***/t/testing-discord-bot/10137/16" 0.404 0.407 "Thisnthat"
[28/Feb/2019:17:07:28 +0000] "DELETE /posts/44144 HTTP/2.0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "posts/destroy" 200 902 "***/t/testing-discord-bot/10137/16" 0.316 0.319 "Thisnthat"
[28/Feb/2019:17:07:35 +0000] "PUT /posts/44144 HTTP/2.0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "posts/update" 200 1957 "***/t/testing-discord-bot/10137/16" 0.844 0.845 "Thisnthat"
[28/Feb/2019:17:12:55 +0000] "PUT /posts/44144/recover HTTP/2.0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "posts/recover" 200 1602 "***/t/testing-discord-bot/10137/18" 0.520 0.520 "Thisnthat"

```

I also checked the /logs/ page and there was nothing related to this. To be sure I cleared the logs and tested it again and no error logs were generated.

---

<div class="post-metadata">

### Author: ![thisnthat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thisnthat/32/164804_2.png) [@thisnthat](https://meta.discourse.org/u/thisnthat)
#### Post date: [March 3, 2019, 6:48pm UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/8 "2019-03-03T18:48:21Z")

</div>

I was able to track down the cause of this issue. The webhook I am using depends on a specific tag.

The issue appears to be in lib/post\_destroyer.rb. tag\_ids is not set on delete webhook events like it is when going through enqueue\_post\_hooks on the WebHook class. After making the following change, my destroy events started working correctly.

I replaced

```plaintext
    WebHook.enqueue_hooks(:post, :post_destroyed,
      id: @post.id,
      category_id: @post&.topic&.category_id,
      payload: payload
    ) if WebHook.active_web_hooks(:post).exists?

```

with

```plaintext
    WebHook.enqueue_hooks(:post, :post_destroyed,
      id: @post.id,
      category_id: @post&.topic&.category_id,
      tag_ids: @post&.topic&.tags&.pluck(:id),
      payload: payload
    ) if WebHook.active_web_hooks(:post).exists?

```

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [March 6, 2019, 5:24pm UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/10 "2019-03-06T17:24:02Z")

</div>

Thanks for the report. This is fixed in the commit

[https://github.com/discourse/discourse/commit/167d85c21fd1d0ecab206c4cb45384bae41f259c](https://github.com/discourse/discourse/commit/167d85c21fd1d0ecab206c4cb45384bae41f259c)

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [March 11, 2019, 12:30pm UTC](https://meta.discourse.org/t/post-destroyed-webhook-event/110259/11 "2019-03-11T12:30:38Z")

</div>

This topic was automatically closed after 4 days. New replies are no longer allowed.
