冷邮件 API
创建 Webhook
事件发生时推送到你指定的 URL。免费。
POST https://api.won.dev/v1/webhooks
事件发生时,以 JSON 格式 POST 到你的 URL,内容与 GET /events 返回的对象相同。请在 10 秒内返回任意 2xx 状态码;否则会重试,约一天内重试八次,连续失败三天的 Webhook 会被停用。同一个事件可能推送两次,请用 id 去重。每次推送都带有 Won-Signature: t=<unix time>,v1=<hex>,其中 hex 是用本次调用返回的 signing_secret 对 <t>.<raw body> 计算出的 HMAC-SHA256。密钥只显示这一次。* 表示除高频类型(email.sent、email.opened、email.clicked)以外的所有类型,高频类型需要明确指定才会推送。最多 10 个 Webhook。用测试 key 创建的 Webhook 只会收到沙箱中的事件。免费。
- 计费: 免费。
参数
参数放在 JSON 请求体里。
| 参数 | 类型 | 必填 | 说明(API 原文) |
|---|---|---|---|
url | string | 是 | Where to send events: an https:// URL that is reachable from the internet. |
events | (* | sender.approved | sender.rejected | campaign.started | campaign.paused | campaign.resumed | campaign.completed | campaign.canceled | email.sent | email.opened | email.clicked | email.bounced | reply.received | recipient.unsubscribed | account.suspended | task.completed)[] | 否 | The types to send, such as ["reply.received", "email.bounced"]. Default ["*"]. Default: *. |
campaign_id | string | 否 | Only events of this campaign. |
metadata | object | 否 | Your own keys and values, such as {"customer_id": "c_812"}: up to 20 keys of at most 40 characters, each value a string of at most 500. Returned with the webhook. Events do not carry it: the same event goes to every webhook. |
响应
错误说明见错误码。
| 字段 | 类型 | 说明(API 原文) |
|---|---|---|
data | object | The webhook, with the secret its deliveries are signed with. |
data.id | string | Webhook ID, such as whk_2m9x7p1q8w3e5r4k. |
data.url | string | |
data.events | string[] | |
data.campaign_id | string | null | |
data.status | enabled | disabled | |
data.disabled_reason | string | null | |
data.metadata | object | Your own keys and values, as you gave them. Empty when none were. |
data.created_at | string | When it was created, as an ISO 8601 time in UTC. |
data.signing_secret | string | The key deliveries are signed with. Store it now: it is not shown again. |
notice | string | null | A plain sentence when there is something to know about this answer. Null otherwise. |
usage | object | Nothing is charged here. The balance, for reference. |
usage.cost | number | What this call cost, in US dollars. |
usage.balance | number | The balance left after this call, in US dollars. |
usage.replayed | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |
示例
curl https://api.won.dev/v1/webhooks \
-H "Authorization: Bearer $WON_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://agent.example/hooks/won",
"events": [
"reply.received",
"email.bounced"
]
}'{
"data": {
"id": "whk_2m9x7p1q8w3e5r4k",
"url": "https://agent.example/hooks/won",
"events": [
"reply.received",
"email.bounced"
],
"campaign_id": null,
"status": "enabled",
"disabled_reason": null,
"metadata": {},
"created_at": "2026-11-18T13:58:00.000Z",
"signing_secret": "whsec_4Zb1rW8sQ0nT7vYcK3mL9xDfH2gJ6pA5"
},
"notice": null,
"usage": {
"cost": 0,
"balance": 48.08,
"replayed": false
}
}用测试 key(won_test_...)发送这个请求,会在沙箱中运行:不发信,不收费。