> ## Documentation Index
> Fetch the complete documentation index at: https://docs.didit.me/llms.txt
> Use this file to discover all available pages before exploring further.

# 实体 Webhook：用户与企业事件

> Didit 用户与企业实体变更的实时 Webhook，涵盖状态流转与资料更新，包含 payload 字段、签名及重试机制。



实体 Webhook 提示词
        将提示词复制到剪贴板



      
      

\<pre>

\````# Goal — subscribe to entity-level webhooks and apply changes to my database

Entity webhooks fire whenever a User or Business entity changes its status or its profile data. Use them to keep your local mirror of Didit entities in sync.

\## Entity-level event catalog

\| `webhook_type` | Trigger |
\|---|---|
\| `user.status.updated` | User entity status changed (`ACTIVE` / `FLAGGED` / `BLOCKED`). Payload includes `previous_status`. |
\| `user.data.updated` | User entity profile / counters / metadata changed. Includes `changed_fields` and a `changes` map of `{previous, current}`. |
\| `business.status.updated` | Business entity status changed. Payload includes `previous_status`. |
\| `business.data.updated` | Business entity profile or aggregates changed. Includes `changed_fields` and `changes`. |

\`activity.created` is accepted in `subscribed_events` and by the Try Webhook tester, but Didit does not deliver it for live traffic. Do not build on it.

Session-level events (`status.updated`, `data.updated`) and transaction events (`transaction.created`, `transaction.status.updated`) live alongside but are separate — see /integration/webhooks for the full catalog.

\## Register a destination

\```bash
curl -X POST https://verification.didit.me/v3/webhook/destinations/ \
-H "x-api-key: $DIDIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"label": "Entity sync",
"url": "https://yourapp.com/webhooks/didit",
"webhook_version": "v3",
"subscribed_events": [
  "user.status.updated",
  "user.data.updated",
  "business.status.updated",
  "business.data.updated"
]
}'
\```

Persist the returned destination `secret_shared_key` — that's the HMAC signing key.

\## Payload shape

Entity payloads are flat: there is no `data` wrapper and no `event` key. Read `webhook_type`.

\```json
\{
"event_id": "7f3c2c1e-6a1d-4c36-9d8e-0d3b5f4e2a10",
"webhook_type": "user.status.updated",
"timestamp": 1776333600,
"created_at": 1776333594,
"application_id": "0c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
"environment": "live",
"vendor_user_id": "9c7d2a30-...",
"vendor_data": "user-42",
"status": "BLOCKED",
"previous_status": "ACTIVE"
}
\```

\`business.*` events use `vendor_business_id` instead of `vendor_user_id`.
\`user.data.updated` / `business.data.updated` payloads keep `status` and add `changed_fields` (array) and `changes` (`{field: {previous, current}}`). Use these to apply minimal diffs to your DB.

\## Verify the signature

Verify X-Signature-V2 (recommended): HMAC-SHA256 of the canonical JSON body with the destination `secret_shared_key`, then a constant-time compare, and reject an X-Timestamp older than 300 seconds. See /integration/webhooks for the signature headers and code samples. Respond `2xx` within **5 seconds**. On a 5xx, 404, timeout or connection failure Didit retries up to 2 times (about 1 minute, then about 4 minutes later); see /integration/webhooks#retry-policy.

\## Idempotency

Every delivery carries a unique `event_id`. De-dupe on it. Fallback compound key: `(application_id, webhook_type, vendor_data, timestamp)`.

\## Failure modes

\- Wrong `webhook_version` (e.g. v2) → singular fields and older event names; v3 is required for entity events plural-array contract.
\- Slow handler → retried; budget < 5s; do heavy work async.
\- Unknown event type → log and 200; new event types may be added.

\## Apply-decision pseudocode

\```ts
switch (event.webhook_type) {
case "user.status.updated":
await db.users.update({ vendor_data: event.vendor_data }, { status: event.status });
break;
case "user.data.updated":
for (const field of event.changed_fields) {
  await db.users.update({ vendor_data: event.vendor_data }, { [field]: event.changes[field].current });
}
break;
case "business.status.updated":
case "business.data.updated": /* same shape, businesses table, keyed by vendor_business_id */ break;
}
\```

\## Sources of truth

\- /integration/webhooks — destinations, signatures, retries, full event catalog
\- /management-api/webhook/create-destination — endpoint schema
\- /entities/users/operations — operations that emit user events
\- /entities/businesses/operations — operations that emit business events
\- /integration/integration-prompt — canonical end-to-end prompt````

\</pre>



      
      

粘贴到

每当用户或企业实体的状态或资料数据发生变化，都会发出一个 Webhook，以便您的系统实时作出响应。
使用实体 Webhook 可以同步资料数据、将封禁同步到其他系统，或触发下游合规流程。## 事件目录| 事件 | 触发条件 |
| - | - |
| `user.status.updated` | 用户实体的状态发生变化（`ACTIVE` ↔ `FLAGGED` ↔ `BLOCKED`） |
| `user.data.updated` | 用户实体的资料字段发生变化（姓名、出生日期、头像、汇总计数器、元数据） |
| `business.status.updated` | 企业实体的状态发生变化 |
| `business.data.updated` | 企业实体的资料字段发生变化（法定名称、注册号、国家/地区、计数器） |> [!NOTE]
>
> `activity.created` 可以在 `subscribed_events` 中设置，并且在 **Try Webhook** 测试工具中可用，但 Didit 目前不会向实际流量投递该事件。
> 请勿基于它构建时间线同步。Didit 还会发出会话、交易和企业会话事件，这些事件会引用实体字段。请参阅：- [KYB Webhook](https://docs.didit.me/zh/business-verification/webhooks.md)：企业会话事件
- [交易监控 Webhook](https://docs.didit.me/zh/transaction-monitoring/webhooks.md)：交易事件
- [Webhook 参考](https://docs.didit.me/zh/integration/webhooks.md)：签名验证、重试、目标## Payload 结构实体 Webhook 是扁平结构：没有 `data` 包装层，也没有 `event` 键。
请读取 `webhook_type` 来路由事件。```json theme={null}
{
  "event_id": "7f3c2c1e-6a1d-4c36-9d8e-0d3b5f4e2a10",
  "webhook_type": "user.status.updated",
  "timestamp": 1776333600,
  "created_at": 1776333594,
  "application_id": "0c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
  "environment": "live",
  "vendor_user_id": "9c7d2a30-2f98-4d4f-9d2d-1a7c4b1e5b6a",
  "vendor_data": "user-42",
  "status": "BLOCKED",
  "previous_status": "ACTIVE"
}
```| 字段 | 说明 |
| - | - |
| `vendor_user_id` / `vendor_business_id` | Didit 为该实体分配的标识符。`business.*` 事件使用 `vendor_business_id`。 |
| `vendor_data` | 您为该实体设定的标识符。 |
| `status` | `ACTIVE`、`FLAGGED` 或 `BLOCKED`。 |
| `previous_status` | 仅出现在 `*.status.updated` 中。 |
| `changed_fields` 和 `changes` | 仅出现在 `*.data.updated` 中。 |
| `created_at` | 该实体最后一次更新时的 Unix 秒级时间戳。 |
| `timestamp` | Didit 发出该 Webhook 时的 Unix 秒级时间戳。 |### `user.status.updated` / `business.status.updated`每次状态变化都会触发。
payload 包含 `status` 和 `previous_status`。
它不会说明状态变化的原因：如果您需要查明原因，请在控制台中打开该实体。### `user.data.updated` / `business.data.updated`资料字段变化时触发。
`changed_fields` 列出发生变化的字段，`changes` 包含每个字段的 `previous` 值和 `current` 值。```json theme={null}
{
  "event_id": "5d1e8f9a-0c32-4b6a-a7b6-2b9d6f0a3c41",
  "webhook_type": "user.data.updated",
  "timestamp": 1776333700,
  "created_at": 1776333694,
  "application_id": "0c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
  "environment": "live",
  "vendor_user_id": "9c7d2a30-2f98-4d4f-9d2d-1a7c4b1e5b6a",
  "vendor_data": "user-42",
  "status": "ACTIVE",
  "changed_fields": ["full_name", "session_count"],
  "changes": {
    "full_name": { "previous": null, "current": "John Doe" },
    "session_count": { "previous": 2, "current": 3 }
  }
}
````changed_fields` 中可能出现的字段如下：- 用户：`vendor_data`、`display_name`、`full_name`、`date_of_birth`、`metadata`、`portrait_image`、`issuing_states`、`approved_emails`、`approved_phones`、`features`、`session_count`、`approved_count`、`declined_count`、`in_review_count`、`first_session_at`、`last_session_at`。
- 企业：`vendor_data`、`display_name`、`metadata`、`legal_name`、`registration_number`、`country_code`、`session_count`、`approved_count`、`declined_count`、`in_review_count`、`features`、`first_session_at`、`last_session_at`。请使用 `changed_fields` 和 `changes`，只同步发生变化的字段。## 投递、重试与签名所有实体 Webhook 都遵循标准投递约定：- 使用目标的 `secret_shared_key`，通过 `X-Signature-V2` 请求头使用 HMAC-SHA256 进行**签名**（推荐方式）。同时还会发送 `X-Signature` 和已弃用的 `X-Signature-Simple`，以及 `X-Timestamp`。
- 当您的端点返回 5xx 或 404、超时或连接失败时，会**重试**最多 2 次，分别在约 1 分钟和约 4 分钟后进行。完整策略请参阅 [Webhook 参考](https://docs.didit.me/zh/integration/webhooks.md#重试策略)。
- **幂等性**：每个 Webhook 的 payload 中都有唯一的 `event_id`，请在您的系统中进行去重。目标设置和签名验证的代码示例，请参阅 [Webhook 参考](https://docs.didit.me/zh/integration/webhooks.md)。## 订阅通过 Management API 或 Business Console，在 Webhook 目标上订阅实体事件：```bash theme={null}
curl -X POST https://verification.didit.me/v3/webhook/destinations/ \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "Entity sync",
    "url": "https://yourapp.com/webhooks/didit",
    "subscribed_events": [
      "user.status.updated",
      "user.data.updated",
      "business.status.updated",
      "business.data.updated"
    ]
  }'
```## 后续步骤> [card] [Webhook 参考](https://docs.didit.me/zh/integration/webhooks.md)
>
> 目标、签名、重试和验证。> [card] [创建目标](https://docs.didit.me/zh/management-api/webhook/create-destination.md)
>
> 注册新的 Webhook 端点。> [card] [用户操作](https://docs.didit.me/zh/entities/users/operations.md)
>
> 会触发用户 Webhook 的变更。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.