# 是否可以重试所有失败的Webhook请求？

**URL:** https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701
**Category:** Development
**Created:** [2023年五月3日 16:10 UTC](https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701 "2023-05-03T16:10:31Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Lucas\_Alves](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucas_alves/32/285677_2.png) [@Lucas\_Alves](https://meta.discourse.org/u/Lucas_Alves)
#### Post date: [2023年五月3日 16:10 UTC](https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701/1 "2023-05-03T16:10:31Z")

</div>

我这边在接收 webhook 请求和处理所需信息时遇到了问题。问题已修复，但如果能重新触发所有失败的请求，而不是逐个点击，那就太好了。  
有没有什么方法可以实现？

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2023年五月4日 16:11 UTC](https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701/2 "2023-05-04T16:11:24Z")

</div>

嘿 Lucas，

只是为了确认一下，你说的“重新触发”请求是指 ![Redeliver](https://global.discourse-cdn.com/meta/original/4X/3/7/c/37c60e307fb1a8060d58a51309b8b5639f2a66bc.png) 按钮吗？

---

<div class="post-metadata">

### Author: ![Lucas\_Alves](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucas_alves/32/285677_2.png) [@Lucas\_Alves](https://meta.discourse.org/u/Lucas_Alves)
#### Post date: [2023年五月4日 16:26 UTC](https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701/3 "2023-05-04T16:26:08Z")

</div>

是的，正是这个按钮。

---

<div class="post-metadata">

### Author: ![Lucas\_Alves](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucas_alves/32/285677_2.png) [@Lucas\_Alves](https://meta.discourse.org/u/Lucas_Alves)
#### Post date: [2023年五月4日 17:29 UTC](https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701/4 "2023-05-04T17:29:24Z")

</div>

但是我的问题是，是否存在一次性重新处理多个请求的方法。

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2023年五月4日 19:26 UTC](https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701/5 "2023-05-04T19:26:14Z")

</div>

我不知道有内置的方法。你可以创建一个自定义脚本来完成此操作：

1. 通过 API，在 `https://your-discourse.com/admin/api/web_hook_events/X.json` 获取 webhook 事件列表  
其中 X 是你的 webhook ID。

2. 该端点列出了最后 50 个事件。使用 `offset` 查询参数可以进一步查看列表。例如：  
`https://your-discourse.com/admin/api/web_hook_events/1.json?offset=50`

3. 循环遍历每个返回的事件。对于每个事件，向 `https://your-discourse.com/admin/api/web_hooks/2/events/XXX/redeliver` 发送 POST 请求  
其中 XXX 是事件的 ID。

4. 由于 API 速率限制，请在每次 API 调用之间至少等待几秒钟。

已测试并工作 👍

并感谢 @Lucas_Alves 教我 `offset` 参数 🙂

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2023年六月4日 09:47 UTC](https://meta.discourse.org/t/is-it-possible-to-retry-all-failed-webhook-requests/263701/7 "2023-06-04T09:47:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
