Skip to content

创建 Webhook ​

接口说明 ​

创建 Webhook 订阅,并在创建时返回一次签名密钥。

接口信息 ​

字段值
方法POST
路径/openapi/v2/webhooks
Operation IDcreateWebhook
鉴权Bearer OpenAPI key

入参 ​

名称位置必填类型示例说明
Idempotency-Keyheader是stringmutation-2026-07-10-001客户端为请求生成的幂等键。重试同一请求时复用相同值,可以避免创建重复任务。

请求体 ​

application/json ​

字段必填类型示例说明
name否string | nullSource file updates可选 Webhook 名称。
url是stringhttps://hooks.example.com/focowiki接收 Webhook 的 HTTPS 地址。
events是array<document.waiting | document.processing | document.available | document.error | document.deleting | file.deleted | knowledge_base.deleted>["document.available","document.error","document.deleting"]订阅接收的 Webhook 事件类型。

请求示例 ​

bash
curl -X POST "https://openapi.example.com/openapi/v2/webhooks" \
  -H "Authorization: Bearer <openapi-key>" \
  -H "Idempotency-Key: mutation-2026-07-10-001" \
  -H "Content-Type: application/json" \
  --data '{
  "name": "Source file updates",
  "url": "https://hooks.example.com/focowiki",
  "events": [
    "document.available",
    "document.error",
    "document.deleting"
  ]
}'

成功响应 ​

201 ​

返回新 Webhook 订阅及仅本次返回的签名密钥。

字段必填类型说明
webhook是objectWebhook 订阅记录。
signingSecret是string仅创建接口返回一次的 Webhook 签名密钥。相同幂等请求会返回同一个值;列表接口不会返回该值。

成功响应示例 ​

json
{
  "webhook": {
    "webhookId": "webhook-11111111-1111-4111-8111-111111111111",
    "name": "Source file updates",
    "endpointHost": "hooks.example.com",
    "events": [
      "document.available",
      "document.error",
      "document.deleting"
    ],
    "createdAt": "2026-06-17T00:00:00.000Z",
    "lastDeliveryAt": null
  },
  "signingSecret": "<webhook-signing-secret>"
}

错误码 ​

下表列出这个接口已声明的全部错误响应。

HTTP 状态错误码说明
401UNAUTHORIZEDBearer API key 缺失、格式错误、未知、已撤销或已删除。
413PAYLOAD_TOO_LARGE请求体或待读取文件超过当前接口允许的大小。
422VALIDATION_ERROR请求未通过校验。
429RATE_LIMITED请求超过当前配置的速率限制。
500INTERNAL_ERRORAPI 遇到内部错误。
503DATABASE_REPOSITORY_UNAVAILABLE当前接口所需的数据暂时不可用。

后续操作 ​