Skip to content

创建 Webhook

POST /v1/webhooks

注册一个 Webhook URL,在提取事件发生时接收 POST 请求。每个用户最多可以拥有 10 个活跃的 Webhook。

试一试

Swagger UI 中交互式测试此端点。

需要认证

Authorization 头中包含您的 API 密钥。

请求

请求头

必需
AuthorizationBearer <token>
Content-Typeapplication/json

请求体

字段类型必需描述
urlstring接收 Webhook POST 请求的 HTTPS 端点。
eventsstring[]要订阅的事件。至少需要一个。可选值:"extraction.completed""extraction.failed"

代码示例

bash
curl -X POST https://api.docmap.io/v1/webhooks \
  -H "Authorization: Bearer dm_live_abc123def456ghi789jkl012mno345" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-app.com/webhooks/docmap",
    "events": ["extraction.completed", "extraction.failed"]
  }'
typescript
const apiKey = process.env.DOCMAP_API_KEY

const response = await fetch('https://api.docmap.io/v1/webhooks', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://your-app.com/webhooks/docmap',
    events: ['extraction.completed', 'extraction.failed'],
  }),
})

const { data } = await response.json()

// IMPORTANT: Store the signing secret immediately — it cannot be retrieved later
console.log('Signing Secret:', data.secret)
console.log('Webhook ID:', data.webhook.id)
python
import requests

api_key = "dm_live_abc123def456ghi789jkl012mno345"

response = requests.post(
    "https://api.docmap.io/v1/webhooks",
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json={
        "url": "https://your-app.com/webhooks/docmap",
        "events": ["extraction.completed", "extraction.failed"],
    },
)

data = response.json()["data"]

# IMPORTANT: Store the signing secret immediately — it cannot be retrieved later
print(f"Signing Secret: {data['secret']}")
print(f"Webhook ID: {data['webhook']['id']}")

响应

状态码:200 OK

响应体包含在 data 对象中。

WARNING

签名密钥仅在此响应中返回。请立即安全存储 -- 之后无法再次获取。您需要它来验证 Webhook 签名。

字段

字段类型描述
secretstringHMAC-SHA256 签名密钥(64 个十六进制字符)。仅显示一次。
webhookobjectWebhook 元数据对象(详见下方)。

webhook 对象:

字段类型描述
idstringWebhook 的唯一标识符。
userIdstring拥有该 Webhook 的用户 ID。
urlstring注册的端点 URL。
eventsstring[]Webhook 订阅的事件。
activebooleanWebhook 是否处于活跃状态。新创建的 Webhook 始终为 true
createdAtstringWebhook 创建时间的 ISO 8601 时间戳。

示例

json
{
  "data": {
    "secret": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
    "webhook": {
      "id": "webhook-abc123def456",
      "userId": "uid_a1b2c3d4e5f6",
      "url": "https://your-app.com/webhooks/docmap",
      "events": ["extraction.completed", "extraction.failed"],
      "active": true,
      "createdAt": "2025-01-15T10:00:00.000Z"
    }
  }
}

错误

状态码错误码描述
400MAX_WEBHOOKS_REACHED您已达到 10 个活跃 Webhook 的上限。请先删除现有 Webhook 再创建新的。
401UNAUTHORIZED缺少、无效或已过期的 API 密钥/令牌。

DocMap API 文档