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

# contact.created

> 在创建联系人时触发。

在您的 Webhook 端点使用 `contact.created` 处理此事件。

## 触发条件

在创建联系人时触发。

在您[配置 Webhook 端点](https://docs.ycloud.com/zh/api-reference/guides/api-fundamentals/configure-webhooks.md)时订阅 `contact.created`。

## 语法

YCloud 会向您配置的 Webhook URL 发送 HTTP `POST` 请求。以下结构展示了一种载荷变体。尖括号中的值为占位符；其类型列在 **参数** 下。可选字段和其他变体如下文所述。

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "<ID>",
  "type": "contact.created",
  "apiVersion": "<API_VERSION>",
  "createTime": "<CREATE_TIME>",
  "contactCreated": {
    "id": "<ID>",
    "remarkName": "<REMARK_NAME>",
    "nickName": "<NICK_NAME>",
    "realName": "<REAL_NAME>",
    "phoneNumber": "<PHONE_NUMBER>",
    "countryCode": "<COUNTRY_CODE>",
    "countryName": "<COUNTRY_NAME>",
    "email": "<EMAIL>",
    "sourceType": "<SOURCE_TYPE>",
    "sourceId": "<SOURCE_ID>",
    "sourceUrl": "<SOURCE_URL>",
    "lastSeen": "<LAST_SEEN>",
    "lastConnectedNumber": "<LAST_CONNECTED_NUMBER>",
    "ownerEmail": "<OWNER_EMAIL>",
    "tags": [
      "<TAGS>"
    ],
    "createTime": "<CREATE_TIME>",
    "updateTime": "<UPDATE_TIME>",
    "blocked": "<BLOCKED_VALUE>",
    "customAttributes": {
      "attr1": "<ATTR1>",
      "attr2": "<ATTR2>",
      "attr3": "<ATTR3_VALUE>"
    }
  }
}
```

## 参数

在处理 JSON 请求体之前，请验证 `YCloud-Signature` HTTP 请求头。请参阅[签名验证](https://docs.ycloud.com/zh/api-reference/guides/api-fundamentals/configure-webhooks.md)。

### 事件外层结构

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `id` | string | 是 | 事件的唯一 ID。最小长度：`6`。最大长度：`128`。 |
| `type` | string | 是 | 固定为 `contact.created`。 |
| `apiVersion` | string | 是 | 用于渲染此事件的 API 版本。 |
| `createTime` | string (date-time) | 是 | 该事件的创建时间，格式采用 [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339)。例如：`2022-06-01T12:00:00.000Z`。 |

### 事件载荷

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `contactCreated` | object | 否 | 特定于事件的 `contactCreated` 载荷。 |

四个通用外层字段为必填项。载荷字段取决于事件变体。在各个对象表格中， **必填** 仅在其父对象存在时适用。可选字段可以省略；示例中出现并不代表该字段为必填项。

#### contactCreated

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `id` | string | 是 | 对象的唯一 ID。 |
| `remarkName` | string | 否 | 企业为联系人设置的备注名。 |
| `nickName` | string | 否 | 联系人的昵称。 |
| `realName` | string | 否 | 联系人的真实姓名。 |
| `phoneNumber` | string | 否 | 符合 [E.164](https://en.wikipedia.org/wiki/E.164) 格式的唯一电话号码。 |
| `countryCode` | string | 否 | 两位国家/地区字母缩写代码。请参阅 [ISO 3166-1 alpha-2 国家/地区代码](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)。 |
| `countryName` | string | 否 | 完整的国家/地区名称。 |
| `email` | string | 否 | 联系人的电子邮箱地址。如果存在，该邮箱地址必须唯一。 |
| `sourceType` | string | 否 | 联系人创建时的来源类型。 |
| `sourceId` | string | 否 | 联系人创建时的来源 ID。 |
| `sourceUrl` | string | 否 | 联系人创建时的来源 URL。 |
| `lastSeen` | string (date-time) | 否 | 联系人上次向您的企业发送消息的时间，格式采用 [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339)。例如：`2022-06-01T12:00:00.000Z`。 |
| `lastConnectedNumber` | string | 否 | 联系人上次接入的企业电话号码。 |
| `ownerEmail` | string | 否 | 联系人所有者的电子邮箱地址。 |
| `tags` | string\[] | 否 | 联系人的标签。 |
| `createTime` | string (date-time) | 否 | 联系人的创建时间，格式采用 [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339)。例如：`2022-06-01T12:00:00.000Z`。 |
| `updateTime` | string (date-time) | 否 | 联系人的最后更新时间，格式采用 [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339)。例如：`2022-06-01T12:00:00.000Z`。 |
| `blocked` | boolean | 否 | 联系人是否已被屏蔽。 |
| `customAttributes` | object | 否 | 联系人的自定义属性，表现为键值对。 |

## 示例

以下 JSON 是传递给接收方的请求体。ID、电话号码和其他账户值仅供参考。

> [accordion] 联系人创建事件
>
> 创建新联系人时的示例载荷
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "id": "evt_2345678901",
>   "type": "contact.created",
>   "apiVersion": "v2",
>   "createTime": "2024-01-01T12:00:00.000Z",
>   "contactCreated": {
>     "id": "1824266594102064128",
>     "remarkName": "Priority customer",
>     "nickName": "John Doe",
>     "realName": "John Smith",
>     "phoneNumber": "+12025550124",
>     "countryCode": "US",
>     "countryName": "United States",
>     "email": "recipient@example.com",
>     "sourceType": "api",
>     "sourceId": "import_batch_123",
>     "sourceUrl": "https://example.com/signup",
>     "lastSeen": "2024-01-01T11:59:00.000Z",
>     "lastConnectedNumber": "+16315552222",
>     "ownerEmail": "owner@example.com",
>     "tags": [
>       "premium",
>       "newsletter"
>     ],
>     "createTime": "2024-01-01T12:00:00.000Z",
>     "updateTime": "2024-01-01T12:00:00.000Z",
>     "blocked": false,
>     "customAttributes": {
>       "attr1": "value1",
>       "attr2": "value2",
>       "attr3": 123
>     }
>   }
> }
> ```

> [accordion] 联系人创建示例
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "id": "evt_2345678901",
>   "type": "contact.created",
>   "apiVersion": "v2",
>   "createTime": "2024-01-01T12:00:00.000Z",
>   "contactCreated": {
>     "id": "1824266594102064128",
>     "nickName": "John Doe",
>     "realName": "John Smith",
>     "phoneNumber": "+12025550124",
>     "countryCode": "US",
>     "countryName": "United States",
>     "email": "recipient@example.com",
>     "sourceType": "api",
>     "sourceId": "import_batch_123",
>     "sourceUrl": "https://example.com/signup",
>     "lastSeen": "2024-01-01T11:59:00.000Z",
>     "lastConnectedNumber": "+16315552222",
>     "ownerEmail": "owner@example.com",
>     "tags": [
>       "premium",
>       "newsletter"
>     ],
>     "createTime": "2024-01-01T12:00:00.000Z",
>     "updateTime": "2024-01-01T12:00:00.000Z",
>     "blocked": false,
>     "customAttributes": {
>       "company": "YCloud Inc",
>       "age": 25
>     }
>   }
> }
> ```

在验证签名并持久化接收事件后，返回 `2xx` 响应。耗时较长的任务请以异步方式处理。

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
HTTP/1.1 200 OK
```

有关场景演练，请参阅[带注释的示例](https://docs.ycloud.com/zh/api-reference/guides/examples/webhook-examples/contact-created-webhook-examples)。


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