跳到正文

Webhook

通过 API 管理 Webhook

创建、列出、修改和删除密钥的端点,更换签名密钥,发送测试,读取投递日志并重放投递。

/api/v1/webhooks 用于管理密钥的端点:每个密钥最多 10 个,每个端点都有自己的地址、事件和签名密钥。必须使用 full_access 密钥(否则返回 401 restricted_api_key);sending_access 密钥在控制台中设置其 webhook。每个密钥只能看到自己的端点:访问属于其他密钥的端点会返回 404。

控制台(管理 › API 密钥 › Webhook,个人密钥则为开发者 › Webhook)与以前一样显示该密钥的第一个端点;API 则可以管理全部端点。

方法路径作用
POST/api/v1/webhooks创建;签名密钥包含在响应中,仅返回一次
GET/api/v1/webhooks列出(不含签名密钥)
GET/api/v1/webhooks/{id}读取
PATCH/api/v1/webhooks/{id}修改地址、事件、描述、状态
DELETE/api/v1/webhooks/{id}删除,连同其投递日志
POST/api/v1/webhooks/{id}/rotate-secret更换签名密钥,带宽限期
POST/api/v1/webhooks/{id}/test发送一个 webhook.test 事件
GET/api/v1/webhooks/{id}/deliveries投递日志
GET/api/v1/webhooks/{id}/deliveries/{delivery}单次投递,含其内容
POST/api/v1/webhooks/{id}/deliveries/{delivery}/replay重放一次投递

创建端点

cURL

curl https://mail.example.com/api/v1/webhooks \
  -H "Authorization: Bearer $VOAARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "endpoint": "https://app.example.com/webhooks/voaaro",
    "events": ["email.delivered", "email.bounced", "contact.unsubscribed"],
    "description": "Production"
  }'

Node / Bun

const { data: hook, error } = await voaaro.webhooks.create({
  endpoint: "https://app.example.com/webhooks/voaaro",
  events: ["email.delivered", "email.bounced", "contact.unsubscribed"],
  description: "Production",
})
// Keep it right away: it will not be shown again.
console.log(hook!.signing_secret)

Python

hook = voaaro.Webhooks.create({
    "endpoint": "https://app.example.com/webhooks/voaaro",
    "events": ["email.delivered", "email.bounced", "contact.unsubscribed"],
    "description": "Production",
})
print(hook["signing_secret"])  # keep it right away

PHP

$hook = $voaaro->webhooks->create([
    'endpoint' => 'https://app.example.com/webhooks/voaaro',
    'events' => ['email.delivered', 'email.bounced', 'contact.unsubscribed'],
    'description' => 'Production',
]);
echo $hook->signing_secret; // keep it right away

Go

hook, err := client.Webhooks.Create(&voaaro.CreateWebhookRequest{
	Endpoint:    "https://app.example.com/webhooks/voaaro",
	Events:      []string{"email.delivered", "email.bounced", "contact.unsubscribed"},
	Description: "Production",
})
fmt.Println(hook.SigningSecret) // keep it right away

响应 201:

JSON
{
  "object": "webhook",
  "id": "5d2e8a17-4c90-4b3f-a6e1-0f7b9c2d4e58",
  "endpoint": "https://app.example.com/webhooks/voaaro",
  "events": ["email.bounced", "contact.unsubscribed", "email.delivered"],
  "status": "enabled",
  "description": "Production",
  "created_at": "2026-11-12T09:00:00Z",
  "updated_at": "2026-11-12T09:00:00Z",
  "secret_rotation": null,
  "signing_secret": "whsec_…"
}
字段规则
endpoint(或 url)https://,不含凭据,最多 2,000 个字符;地址必须是公网地址(私有地址会在投递时被拒绝)
events1 到 30 个取自事件列表的名称;控制台中的简称(delivered、bounced 等)等同于 email.delivered、email.bounced 等。超出密钥权限的事件(例如 sending_access 密钥订阅 contact.created):返回 422
description最多 200 个字符;设为 null 即清除
statusenabled(默认)或 disabled

地址格式错误时返回 400;超过 10 个端点时返回 422。签名密钥(whsec_…)只在此处和轮换时返回,之后无法再次读取(这一点与 Resend 不同)。如需重试中断的创建请求而不重复创建,请发送 Idempotency-Key:重试会返回相同的响应,包括签名密钥。

读取、修改、删除

GET /api/v1/webhooks(不带 limit 时返回全部,带上则使用游标)和 GET /api/v1/webhooks/{id} 返回相同的对象,不含 signing_secret。只要旧签名密钥仍在签名,secret_rotation 的值就为 { "previous_secret_expires_at": "…" },否则为 null。

PATCH /api/v1/webhooks/{id} 接受相同的字段,均为可选;events 会替换整个列表。设置 "status": "disabled" 可以暂停端点而不删除它:它将不再收到任何事件,webhook.test 除外。

cURL
curl -X PATCH https://mail.example.com/api/v1/webhooks/$WEBHOOK_ID \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{"events": ["email.bounced", "email.complained"], "status": "enabled"}'

DELETE /api/v1/webhooks/{id} 返回 { "object": "webhook", "id": "…", "deleted": true };其投递日志也会一并删除。

更换签名密钥

POST /api/v1/webhooks/{id}/rotate-secret 会生成一个新的签名密钥,并立即用它签名。旧签名密钥在 grace_hours 小时内(默认 24,范围 0 到 72)也会继续签名:在此期间每个请求都带有两个签名,您的应用可以在部署新签名密钥的过程中继续使用旧的(详情)。如果签名密钥已泄露,设置 "grace_hours": 0 可立即停用旧签名密钥。

cURL

curl https://mail.example.com/api/v1/webhooks/$WEBHOOK_ID/rotate-secret \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{"grace_hours": 24}'

Node / Bun

const { data } = await voaaro.webhooks.rotateSecret(webhookId, { graceHours: 24 })

Python

r = voaaro.Webhooks.rotate_secret(webhook_id, {"grace_hours": 24})

PHP

$r = $voaaro->webhooks->rotateSecret($webhookId, ['graceHours' => 24]);

Go

r, err := client.Webhooks.RotateSecret(webhookID, &voaaro.RotateWebhookSecretRequest{GraceHours: voaaro.Int(24)})
JSON
{
  "object": "webhook",
  "id": "5d2e8a17-4c90-4b3f-a6e1-0f7b9c2d4e58",
  "signing_secret": "whsec_…",
  "previous_secret_expires_at": "2026-11-13T09:00:00Z"
}

测试

POST /api/v1/webhooks/{id}/test 会将一个 webhook.test 事件(data: {})加入队列,并返回 202 { "object": "webhook_delivery", "id": "…" }:您可以在日志中跟踪这次投递。

投递日志

每次向端点发送都是一次投递,保留 30 天。GET /api/v1/webhooks/{id}/deliveries 按从新到旧的顺序列出投递,不带 limit 时每页 20 条。筛选条件:status(pending、sending、delivered、failed)和 event_type(email.bounced、contact.created 等)。

cURL
curl "https://mail.example.com/api/v1/webhooks/$WEBHOOK_ID/deliveries?status=failed&limit=50" \
  -H "Authorization: Bearer $VOAARO_API_KEY"
JSON
{
  "object": "webhook_delivery",
  "id": "9a4f1c27-3e8b-4d06-b5a2-7c1e0d9f6b43",
  "webhook_id": "5d2e8a17-4c90-4b3f-a6e1-0f7b9c2d4e58",
  "event_type": "email.bounced",
  "status": "failed",
  "attempts": 9,
  "last_status": 503,
  "last_error": null,
  "created_at": "2026-11-10T08:00:00Z",
  "delivered_at": null,
  "next_attempt_at": null,
  "replay_of": null
}
字段含义
statuspending(等待尝试)、sending(进行中)、delivered(已收到 2xx 响应)、failed(9 次尝试后已放弃)
attempts已进行的尝试次数
last_status、last_error最后一次响应的 HTTP 状态码,或网络错误
next_attempt_at下一次尝试的时间,适用于等待中的投递
replay_of被重放的原始投递,适用于重放产生的投递

GET /api/v1/webhooks/{id}/deliveries/{delivery} 还会返回 payload:实际发送的请求体(type、created_at、data)。

重放投递

POST /api/v1/webhooks/{id}/deliveries/{delivery}/replay 会以相同的内容(相同的 type、created_at 和 data)创建一次新的投递,并在几秒内发出。响应为 202 { "object": "webhook_delivery", "id": "<新投递>", "replay_of": "<原投递>" }。原投递保持不变。

  • 新投递有自己的 Voaaro-Event-Id 和新的签名:如果您的应用按 Voaaro-Event-Id 忽略已处理的事件,重放的投递会被正常处理;如果需要按内容去重,请比较 type、created_at 以及 data 中的标识符(id 或 email_id)。
  • 每个密钥每分钟最多重放 20 次(超出则返回 429 rate_limit_exceeded)。
  • 如果您这边发生了故障:列出该时间段内 failed 状态的投递,然后逐一重放。
cURL
curl -X POST https://mail.example.com/api/v1/webhooks/$WEBHOOK_ID/deliveries/$DELIVERY_ID/replay \
  -H "Authorization: Bearer $VOAARO_API_KEY"

每次创建、修改、删除、轮换和重放都会以该密钥的名义记入审核日志(webhook.save、webhook.delete、webhook.rotate、webhook.replay)。

Esc