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

# CMS Webhooks

> Receive content update webhooks from external CMS providers.

The CMS Webhook endpoint receives real-time content update notifications from external CMS providers (Contentful, Strapi, Sanity, etc.). Each content source has a unique webhook URL.

## POST /api/v1/cms/webhook/{sourceId}

Receive a webhook notification when content is created or updated in the CMS.

### Path Parameters

| Parameter  | Type   | Required | Description                     |
| ---------- | ------ | -------- | ------------------------------- |
| `sourceId` | string | Yes      | Content source ID (UUID format) |

### Headers

| Header                | Required | Description                           |
| --------------------- | -------- | ------------------------------------- |
| `X-Webhook-Signature` | Yes      | HMAC-SHA256 signature of the raw body |

### Request Body

The body format depends on the CMS provider. The platform extracts the external content ID from common fields:

* `id` (generic)
* `sys.id` (Contentful)
* `_id` (Sanity/MongoDB-style)

### Behavior

1. Verifies the webhook signature against the source's stored secret
2. Extracts the external content ID from the payload
3. Fetches the full content item from the CMS via the configured adapter
4. Upserts the content item into KaireonAI (creates or increments version)
5. If `autoPublish` is enabled on the source, the content is published immediately

### Response

```json theme={null}
{ "received": true }
```

### Error Responses

| Status | Description                                   |
| ------ | --------------------------------------------- |
| 400    | Invalid source ID format                      |
| 401    | Invalid webhook signature                     |
| 403    | Webhook secret not configured for this source |
| 404    | Content source not found                      |

### Setting Up CMS Webhooks

1. Create a content source via `POST /api/v1/content-sources` with a `webhookSecret`
2. Configure your CMS to send webhooks to: `https://your-domain.com/api/v1/cms/webhook/{sourceId}`
3. Set the `X-Webhook-Signature` header to `sha256=<hmac-hex>` using the webhook secret
