跳到主要内容

接口参考:Webhook

所有 Webhook 接口的 scope 都是 webhook。

GET /api/v2/webhooks​

列出当前用户的端点。

响应 data​

[
{
"id": "12",
"url": "https://your-domain.com/keydatas/events",
"events": ["task.run.completed"],
"taskId": 0,
"status": "active",
"createdAt": 1760000000000,
"updatedAt": 1760000000000,
"secretMasked": "****abcd"
}
]

id 是字符串;secret 不会返回,只有 secretMasked。

错误​

HTTPcode场景
401unauthorizedKey 无效

POST /api/v2/webhooks​

创建端点。

请求体​

字段类型必填说明
urlstring是仅 HTTPS;≤1024;端口 80/443/8080/8443
eventsstring[]是task.run.completed / task.run.failed / export.completed
taskIdinteger否0 或省略=全部任务;>0 必须属于当前用户

响应 data​

与列表项相同,并额外返回一次 secret(64 位小写 hex)。

错误​

HTTPcode场景
400invalid_paramurl/events 缺失、taskId 负数
403forbidden套餐端点数用尽
404not_foundtaskId 不属于当前用户
422invalid_url非 HTTPS/内网/超长/端口不允许/DNS 失败
422invalid_paramevents 为空或含未接线类型
429rate_limited限流
503service_unavailable事件订阅总开关关闭

不支持 Idempotency-Key;重试会创建两个端点。

示例​

curl -X POST https://open.keydatas.com/api/v2/webhooks \
-H "Authorization: Bearer $KEYDATAS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-domain.com/keydatas/events",
"events": ["task.run.completed","export.completed"]
}'

DELETE /api/v2/webhooks/{id}​

软删除端点(status=disabled)。

路径参数​

参数类型说明
idinteger端点 ID

响应​

data 为空或确认信息。重复删除返回 404。

错误​

HTTPcode场景
401unauthorizedKey 无效
404not_found端点不存在/不属于当前用户/已删除

POST /api/v2/webhooks/{id}/test​

发送 webhook.test 事件。

响应 data​

{"eventId": "32位hex", "status": "queued"}

queued 只表示已入队,不代表投递成功。

错误​

HTTPcode场景
401unauthorizedKey 无效
404not_found端点不存在
503service_unavailable事件订阅总开关关闭

GET /api/v2/webhooks/{id}/events​

查询端点的事件与死信。

查询参数​

参数类型默认说明
statusstringallPENDING / SENDING / DONE / DEAD
eventTypestringall三类事件 + webhook.test
createdFrominteger0Unix 毫秒,含
createdTointeger0Unix 毫秒,含
limitinteger201~100
beforeIdinteger0上一页最后一条 id

响应 data​

{
"items": [
{
"id": 9001,
"eventId": "32位hex",
"eventType": "task.run.completed",
"status": "DEAD",
"attempts": 6,
"taskId": 738590,
"lastError": "connection refused",
"nextRetryAt": 0,
"createdAt": 1760000000000,
"updatedAt": 1760003600000,
"payloadJson": "{...}"
}
],
"hasMore": false,
"nextBeforeId": 0
}

错误​

HTTPcode场景
400invalid_paramstatus/eventType 非法、from > to
401unauthorizedKey 无效
404not_found端点不存在

POST /api/v2/webhooks/{id}/events/{eventId}/replay​

回放单条死信。

路径参数​

参数类型说明
idinteger端点 ID
eventIdstring32 位小写 hex

规则​

  • 只有 DEAD 可回放;
  • 回放后 attempts=0,X-Keydatas-Delivery-Attempt 从 1 开始;
  • 端点已软删 → 409;事件不存在/非 DEAD/状态已变化 → 409;
  • 总开关关闭 → 503。

POST /api/v2/webhooks/{id}/events/replay​

批量回放死信。

请求体​

{"eventIds": ["32位hex", "另一个32位hex"]}
  • 必填、非空、≤50 条;
  • 重复项自动去重;
  • 逐条条件 UPDATE,允许部分成功。

响应 data​

{
"replayed": 3,
"failed": 1,
"failures": [
{"eventId": "32位hex", "reason": "not_dead_or_missing"}
]
}

reason:invalid_event_id / not_dead_or_missing。

错误​

HTTPcode场景
400invalid_parameventIds 为空/超过 50
401unauthorizedKey 无效
404not_found端点不存在
409conflict端点已软删
503service_unavailable总开关关闭

相关​