# Create a webhook endpoint

POST /v1/webhook-endpoints. Creates an endpoint that receives events.

`POST https://api.chatwise.so/v1/webhook-endpoints`

Creates an endpoint that receives events. The response is the only time `signingSecret` is returned, so store it right away.

The endpoint receives events that happen after it was created. A workspace can have 10 endpoints.

The API key needs the `webhooks:write` scope. It also needs `messages:read` when you subscribe to `message.*` events. See [authentication and scopes](https://chatwise.so/docs/authentication.md).

## Example

**curl**:

```bash
curl -X POST 'https://api.chatwise.so/v1/webhook-endpoints' \
  -H "Authorization: Bearer $CHATWISE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Order support",
  "url": "https://example.com/webhooks/chatwise",
  "events": [
    "message.received"
  ]
}'
```

**Node.js**:

```js
const response = await fetch("https://api.chatwise.so/v1/webhook-endpoints", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CHATWISE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "Order support",
    "url": "https://example.com/webhooks/chatwise",
    "events": [
      "message.received"
    ]
  }),
});
const body = await response.json();
if (!response.ok) throw new Error(`${response.status}: ${body.message}`);
console.log(body.data);
```

**Python**:

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://api.chatwise.so/v1/webhook-endpoints",
    method="POST",
    headers={
        "Authorization": f"Bearer {os.environ['CHATWISE_API_KEY']}",
        "Content-Type": "application/json",
    },
    data=json.dumps({
      "name": "Order support",
      "url": "https://example.com/webhooks/chatwise",
      "events": [
        "message.received"
      ]
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    print(json.load(response)["data"])
```

## Body

JSON. Unknown fields are refused with a 400.

| Field | Type | Description |
| --- | --- | --- |
| `name` | string | **Required.** A name for the endpoint, 1 to 80 characters. Spaces around it are ignored. Can't be blank, or contain control characters or unpaired surrogates. |
| `url` | string | **Required.** Where to send events: a public `https://` URL on port 443, without a username, password or `#fragment`. Spaces around it are ignored. At most 2048 characters. |
| `events` | array of strings | **Required.** The events to receive. `message.*` events also need the `messages:read` scope. Each one of `message.received`, `message.sent`, `message.delivered`, `message.read`, `message.failed`, `comment.received`. |
| `accountIds` | array of strings | Only send events for these accounts. Leave out, or send an empty list, for every account. At most 50. |

## Response

**201.** The endpoint, with its signing secret.

```json
{
  "data": {
    "id": "we_01JE2Z3K8Q9V7W5X4Y3Z2A1B0C",
    "name": "Order support",
    "url": "https://example.com/webhooks/chatwise",
    "events": [
      "message.received"
    ],
    "accountIds": [],
    "status": "ACTIVE",
    "apiVersion": "2026-12-01",
    "health": {
      "lastSuccessAt": null,
      "lastFailureAt": null,
      "consecutiveFailures": 0,
      "disabledAt": null,
      "disabledReason": null
    },
    "createdAt": "2026-11-02T10:00:00.000Z",
    "updatedAt": "2026-11-02T10:00:00.000Z",
    "signingSecret": "whsec_ZXhhbXBsZS1zZWNyZXQtZG8tbm90LXVzZS0wMDAwMDA="
  }
}
```

| Field | Type | Description |
| --- | --- | --- |
| `data.id` | string | The endpoint's id. |
| `data.name` | string | The endpoint's name. |
| `data.url` | string | Where events are sent. |
| `data.events` | array of strings | The events it receives. Each one of `message.received`, `message.sent`, `message.delivered`, `message.read`, `message.failed`, `comment.received`. |
| `data.accountIds` | array of strings | The accounts it receives events for. Empty means every account. |
| `data.status` | string | `ACTIVE`, `PAUSED` by the workspace, or `DISABLED` by Chatwise (see `health.disabledReason`). |
| `data.apiVersion` | string | The payload format it receives, as a date. |
| `data.health` | object | How its deliveries are going. |
| `data.health.lastSuccessAt` | string or null | When an attempt last succeeded. ISO 8601, in UTC. |
| `data.health.lastFailureAt` | string or null | When an attempt last failed. ISO 8601, in UTC. |
| `data.health.consecutiveFailures` | integer | Failed attempts since the last success. |
| `data.health.disabledAt` | string or null | When Chatwise disabled it. ISO 8601, in UTC. |
| `data.health.disabledReason` | string or null | Why Chatwise disabled it. |
| `data.createdAt` | string | When it was created. ISO 8601, in UTC. |
| `data.updatedAt` | string | When it, or its health, last changed. ISO 8601, in UTC. |
| `data.signingSecret` | string | The secret that signs its deliveries: `whsec_` and 32 random bytes in base64. Shown only here; store it safely. |

## Errors

| Status | Message | What it means |
| --- | --- | --- |
| 400 | Expected property name or '}' in JSON at position 1 (line 1 column 2) | The request body isn't valid JSON. The message says where. |
| 400 | Validation failed | A parameter or body field is missing, unknown or malformed. `errors` lists each one. |
| 400 | Use a public https:// URL on port 443, without a username, password or #fragment. | The URL can't receive webhooks. |
| 400 | Every account id must be one of this workspace's connected accounts. | An id in `accountIds` isn't one of the workspace's accounts. |
| 400 | A workspace can have at most 10 webhook endpoints. | Delete an endpoint you no longer use. |
| 400 | Message events need an API key with the messages:read scope too. | The key lacks `messages:read`, which `message.*` events need. |
| 401 | A valid Bearer API key is required | The `Authorization` header is missing or isn't `Bearer <API key>`. |
| 401 | Invalid or revoked API key | The key doesn't exist, was revoked, or has expired. |
| 401 | Invalid API key | Chatwise couldn't check the key. Try again. |
| 403 | API key does not have the required scope: webhooks:write | The key lacks the route's scope. Create a key that has it. |
| 413 | request entity too large | The request body is larger than 100 KB. |
| 429 | API key rate limit exceeded | Wait the number of seconds in the `Retry-After` header. |
| 500 | Internal server error | Something failed in Chatwise. Retry reads with backoff. |

The body of an error is described in [errors](https://chatwise.so/docs/errors.md).
