> ## 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 and note update webhook examples

> Handle contact attribute changes and contact-note updates.

> [!NOTE]
>
> For the exhaustive schema-derived catalog, see [all examples](https://docs.ycloud.com/en/api-reference/guides/examples/webhook-examples/webhook-payload-examples).

## What it is

Handle `contact.attributes_changed` and `contact.note.updated` events.

## Before you begin

* Create a public HTTPS endpoint in your application.
* Configure a YCloud webhook endpoint for the event types you need.
* Store the endpoint signing secret securely.
* Make event processing idempotent.

## How it works

YCloud sends an HTTP `POST` request when the event occurs. Verify the signature, durably record the event, return a `2xx` response, and process slow work asynchronously.

## Request

The scenarios below show requests delivered to your webhook URL. Treat the event `id` as the delivery identifier and use `type` to route the payload.

## Response

Return a `2xx` status after accepting the event.

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

> [!NOTE]
>
> For endpoint setup, signature validation, and retry behavior, see [Configure webhooks](https://docs.ycloud.com/en/api-reference/guides/api-fundamentals/configure-webhooks.md).

Occurs when a contact's attributes are modified. The webhook payload contains information about what attributes were changed, including their old and new values.

## Tags Change Example (Add Tags)

### Request

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_1234567892",
  "type": "contact.attributes_changed",
  "apiVersion": "v2",
  "createTime": "2024-01-01T12:00:00.000Z",
  "contactAttributesChanged": {
    "id": "1824266594102064128",
    "updateTime": "2024-01-01T12:00:00.000Z",
    "changedAttributes": {
      "tags": {
        "oldValue": ["premium", "newsletter"],
        "newValue": ["premium", "newsletter", "vip"],
        "extra": [
          {
            "action": "ADDED",
            "id": "686dd294334be8606a5bf312",
            "value": "vip"
          }
        ]
      }
    }
  }
}
```

### Response

Acknowledge the delivery after durably accepting the event.

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

### Explanation

Route the event by `type`, deduplicate it by `id`, and move slow or failure-prone work to an asynchronous processor.

## Tags Change Example (Remove Tags)

### Request

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_1234567893",
  "type": "contact.attributes_changed",
  "apiVersion": "v2",
  "createTime": "2024-01-01T12:00:00.000Z",
  "contactAttributesChanged": {
    "id": "1824266594102064128",
    "updateTime": "2024-01-01T12:00:00.000Z",
    "changedAttributes": {
      "tags": {
        "oldValue": ["premium", "newsletter", "vip"],
        "newValue": ["premium", "newsletter"],
        "extra": [
          {
            "action": "REMOVED",
            "id": "686dd294334be8606a5bf312",
            "value": "vip"
          }
        ]
      }
    }
  }
}
```

### Response

Acknowledge the delivery after durably accepting the event.

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

### Explanation

Route the event by `type`, deduplicate it by `id`, and move slow or failure-prone work to an asynchronous processor.

## Change Example

### Request

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_1234567900",
  "type": "contact.attributes_changed",
  "apiVersion": "v2",
  "createTime": "2024-01-01T12:00:00.000Z",
  "contactAttributesChanged": {
    "id": "1824266594102064128",
    "updateTime": "2024-01-01T12:00:00.000Z",
    "changedAttributes": {
      "waba_id": {
        "oldValue": "waba_old_123456",
        "newValue": "waba_new_789012",
        "extra": [
          {
            "action": "CHANGED"
          }
        ]
      }
    }
  }
}
```

### Response

Acknowledge the delivery after durably accepting the event.

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

### Explanation

* **Correct Structure**: The `contactAttributesChanged` object contains three required fields: `id`, `updateTime`, and `changedAttributes`.
* **Changed Attributes**: The `changedAttributes` field is an object where each key is the attribute name and the value is a `ContactAttributeChange` object.
* **Event Property Configuration**: When enabling `contact.attributes_changed` events, you must configure the `eventProperties` field in your webhook endpoint to specify which attributes should be included in the webhook payload.
* **Attribute Types**: The `oldValue` and `newValue` fields can contain different data types:
  * String: text values
  * Number: numeric values (integer or decimal)
  * Boolean: true/false values
  * Array: arrays of strings
  * Object: complex objects with nested properties
  * Null: when an attribute is removed or unset
* **Tags Changes**: For tag attributes, the `extra` field provides detailed information about which tags were added or removed, including their IDs and values.
* **Null Values**: When an attribute is removed or set to null, the `newValue` will be `null`. When an attribute is newly added, the `oldValue` may be `null`.
* **Custom Attributes**: Custom attributes are included in the `changedAttributes` object just like standard attributes, with their custom keys as the attribute names.
* **Change Detection**: Only attributes that have actually changed are included in the `changedAttributes` object.
* **Extra Field**: The `extra` field is optional and is primarily used for tag-related changes to provide additional context about the specific actions performed.

## Contact note updated

Use `contact.note.updated` when a contact note is updated.

### Request

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_2234567890abcdef12345678",
  "type": "contact.note.updated",
  "apiVersion": "v2",
  "createTime": "2024-01-02T12:00:00.000Z",
  "contactNote": {
    "id": "6a3de646e18f344f743aaa4d",
    "contactId": "1824266594102064128",
    "username": "alice_01",
    "phoneNumber": "+16315551111",
    "content": "Customer now prefers afternoon follow-up.",
    "createTime": "2024-01-01T12:00:00.000Z",
    "updateTime": "2024-01-02T12:00:00.000Z"
  }
}
```

### Response

Acknowledge the delivery after durably accepting the event.

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

### Explanation

Use `contactNote.id` to identify the note and `contactId` to identify its owning contact. `username` and `phoneNumber` describe the contact and can be null. The payload contains the customer-facing note snapshot, including `content`, without internal operator identifiers.


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