如何通过Stripe API/CLI列出Webhook尝试详情以重发特定端点未成功请求?
针对特定Stripe Webhook端点重发未成功投递事件的解决方案
当前你遇到的核心问题是:无法通过API/CLI直接获取Web UI级别的Webhook投递详情,仅能筛选出存在失败投递的事件(pending_webhooks > 0),但无法直接关联到目标端点ID,没法精准重发指定端点的未成功投递事件。以下是可行的解决步骤:
1. 获取目标Webhook端点ID
如果尚未获取目标端点ID,可通过Stripe CLI执行命令列出所有Webhook端点:
stripe webhook endpoints list
找到对应端点的id字段(格式示例:we_xxxxxx)。
2. 获取包含投递详情的事件列表
通过Stripe API或CLI请求事件时,添加expand参数展开webhook_deliveries字段,这样每个事件会返回所有Webhook投递的完整记录,包括关联的端点ID、投递状态等关键信息:
- CLI命令:
stripe events list --pending-webhooks --expand "data.webhook_deliveries" --json
- curl API请求示例:
curl -G https://api.stripe.com/v1/events \ -u sk_your_secret_key: \ -d pending_webhooks=true \ -d expand[]=data.webhook_deliveries
3. 筛选目标端点的未成功投递事件
利用jq工具对返回的JSON数据进行过滤,仅保留目标端点下状态不为succeeded的事件:
stripe events list --pending-webhooks --expand "data.webhook_deliveries" --json | jq '.data[] | select(.webhook_deliveries[] | .endpoint_id == "we_xxxxxx" and .status != "succeeded")'
将命令中的we_xxxxxx替换为你的目标端点ID。
4. 批量重发事件到目标端点
提取筛选出的事件ID,通过循环批量执行重发命令:
stripe events list --pending-webhooks --expand "data.webhook_deliveries" --json | jq -r '.data[] | select(.webhook_deliveries[] | .endpoint_id == "we_xxxxxx" and .status != "succeeded") | .id' | while read event_id; do stripe events resend $event_id --webhook-endpoint we_xxxxxx done
替换对应端点ID后即可自动完成批量重发操作。
内容的提问来源于stack exchange,提问作者ahong
相关产品推荐
相关产品推荐

