# Knowledge source change

Source: https://docs.coderhelm.com/api/reference/webhooks/receive-knowledge-webhook

`POST /webhooks/knowledge/{token}`

Tells CoderHelm that pages of a connected knowledge source changed, so it syncs that source now instead of at its next scheduled sync. Sanity posts to the address shown for each Sanity source (CoderHelm registers it itself when the token may manage webhooks), signed with `sanity-webhook-signature`: `t=<ms>,v1=` and the base64url HMAC-SHA256 of `<t>.<body>`, keyed with the token in the address; a signature older than five minutes is refused. Notion posts to `/webhooks/knowledge/notion` for the whole install, signed with `X-Notion-Signature`: `sha256=` and the hex HMAC-SHA256 of the body, keyed with the subscription's verification token. An event only starts a sync: what changed is always read back from the provider with the source's own connection.

## Authentication

Verified by the request itself (see the description above). See [Webhooks](https://docs.coderhelm.com/api/webhooks).

## Parameters

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `token` | string | yes | The source's webhook token, or `notion` for the install's Notion subscription. |

## Request body

`application/json`: The provider's event.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `_id` | string or null | no | Sanity: the changed document's id. |
| `_rev` | string or null | no | Sanity: the document's new revision. |
| `_type` | string or null | no | Sanity: the changed document's type. |
| `type` | string or null | no | Notion: the event, such as `page.content_updated`. |
| `workspace_id` | string or null | no | Notion: the workspace the event is about. |

## Responses

### 200

Accepted; a sync starts unless the source is paused.

### 401

The signature is missing, wrong or too old.

### 404

No source has this address.

## Example request

cURL:

```bash
curl -X POST 'https://api.coderhelm.com/webhooks/knowledge/string' \
  -H 'Content-Type: application/json' \
  -d '{
  "_id": "post-returns",
  "_rev": "q8PZ1v3VaaO9ShV3lKgqXm",
  "_type": "post"
}'
```

TypeScript:

```ts
const res = await fetch("https://api.coderhelm.com/webhooks/knowledge/string", {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
      "_id": "post-returns",
      "_rev": "q8PZ1v3VaaO9ShV3lKgqXm",
      "_type": "post"
    }),
});
if (!res.ok) {
  const { error, code } = await res.json();
  throw new Error(`${res.status} ${code}: ${error}`);
}
const data = await res.json();
```

Python:

```python
import requests

body = {
    "_id": "post-returns",
    "_rev": "q8PZ1v3VaaO9ShV3lKgqXm",
    "_type": "post",
}
res = requests.request("POST", "https://api.coderhelm.com/webhooks/knowledge/string", json=body)
if not res.ok:
    raise RuntimeError(f"{res.status_code}: {res.json().get('error')}")
data = res.json()
```
