# Create webhook

> Registers a URL that receives task events as they happen, so you do not have to poll. Deliveries are signed; the signing secret is returned here and nowhere else.

Registers an endpoint that Mynth POSTs to when a task settles. Deliveries are
signed with the `wbs_` secret in this response. The API returns it only here,
so store it now. The dashboard also shows it on the endpoint's page.

[Webhooks](https://mynth.io/docs/concepts/webhooks.md) has the signature check, events, and
sources. [Webhook payloads](https://mynth.io/docs/api-reference/webhook-payloads.md) has the body
of each event.

`POST /webhook`

**Auth:** API key or OAuth token

## Request body

- `events` (required, array | string) — The events to send to the webhook. When 'all', all events will be sent to the webhook. One of: `"all"`.
- `url` (required, string) — The URL to send the webhook to. Must be a valid URL.
- `oauthEnabled` (boolean) — Whether tasks authenticated with OAuth (playground and CLI sessions) deliver to this webhook. Default `false`.
- `enabled` (boolean) — Whether the webhook is enabled. When disabled, no events will be sent to the webhook. Default `true`.
- `apiKeyIds` (string[] | null) — API keys this webhook is scoped to. When empty or null, every API key delivers to it. ≤ 1000 items.

## Response

### 201 — Webhook created

- `data` (required, object)
  - `apiKeyIds` (required, string[] | null)
  - `createdAt` (required, any)
  - `enabled` (required, boolean)
  - `events` (required, string[] | null)
  - `id` (required, string)
  - `oauthEnabled` (required, boolean)
  - `secret` (required, string)
  - `updatedAt` (required, any)
  - `url` (required, string)
  - `userId` (required, string)

```json
{
  "data": {
    "apiKeyIds": [
      "string"
    ],
    "enabled": false,
    "events": [
      "all"
    ],
    "id": "string",
    "oauthEnabled": false,
    "secret": "string",
    "url": "string",
    "userId": "string"
  }
}
```

## Request samples

### cURL

```bash
curl -X POST https://api.mynth.io/webhook \
  -H "Authorization: Bearer $MYNTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "events": "all",
    "url": "string"
  }'
```

### JavaScript

```ts
const response = await fetch("https://api.mynth.io/webhook", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MYNTH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "events": "all",
    "url": "string"
  }),
});

const { data } = await response.json();
```

The full schema for this endpoint is in the [OpenAPI document](https://api.mynth.io/openapi.json).
