# Register a webhook endpoint

> Registers an HTTPS URL that receives signed notifications: `batch.completed` and `batch.failed` for batch jobs, and `monitor.changed` and `monitor.failed` for monitors.

Source: https://docs.spicrawl.com/api-reference/webhooks/webhooks-create

## POST /v1/webhooks

Operation ID: `webhooksCreate`. API key scope: `webhooks`.

Registers an HTTPS URL that receives signed notifications: `batch.completed` and `batch.failed` for batch
jobs, and `monitor.changed` and `monitor.failed` for monitors. Notify-only: the payload carries the job or
monitor summary, and you fetch anything else yourself.

The response is the endpoint plus `secret`, the signing secret. It is returned here and from
`rotate-secret` only, and is never shown again. Store it before you return from the call. Verify every
delivery with it (see the webhooks guide, "Verify signatures").

`events` defaults to `["batch.completed", "batch.failed"]`. `format` defaults to `json`. Use `slack` or
`discord` to post a one-line summary to a Slack or Discord incoming-webhook URL; the signature headers are
sent in every format.

A `ping` delivery is always sent by `POST /v1/webhooks/{webhookID}/test` and is not listed in `events`.

The URL must be `https://`, at most 2,048 characters, and must not point at a private or internal address.
An organization may hold at most 20 endpoints.

### Example

```bash
curl -X POST "https://api.spicrawl.com/v1/webhooks" \
  -H "Authorization: Bearer $SPICRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://hooks.example.com/spicrawl","name":"nightly-catalog","events":["batch.completed","batch.failed"]}'
```

### Request body

`application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `url` | string (uri) | yes |  |
| `name` | string | no |  |
| `events` | array of string: `batch.completed`, `batch.failed`, `monitor.changed`, `monitor.failed` (`WebhookEvent`) | no | Defaults to `["batch.completed", "batch.failed"]`. |
| `format` | string: `json`, `slack`, `discord` | no | Body shape. `json` is the signed JSON document. `slack` posts `{"text": summary}` and `discord` posts `{"content": summary}` (at most 2,000 characters) for incoming-webhook URLs. Signature headers are sent in every format. |

Example `batchJson`: Batch events as JSON

```json
{
  "url": "https://hooks.example.com/spicrawl",
  "name": "nightly-catalog",
  "events": [
    "batch.completed",
    "batch.failed"
  ]
}
```

Example `slackAlerts`: Failed batches to a Slack incoming webhook

```json
{
  "url": "https://hooks.slack.com/services/T000/B000/XXXX",
  "name": "ops-alerts",
  "events": [
    "batch.failed"
  ],
  "format": "slack"
}
```

### Responses

#### 201

The endpoint and its signing secret. This is the only response that carries `secret`.

Headers: `X-Request-Id`.

`application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | yes | Endpoint id. Use it in the `webhookID` path parameter and as `webhook_endpoint_id` on a batch. |
| `name` | string \| null | no |  |
| `url` | string (uri) | yes | HTTPS URL that receives the deliveries. |
| `events` | array of string: `batch.completed`, `batch.failed`, `monitor.changed`, `monitor.failed` (`WebhookEvent`) | yes |  |
| `format` | string: `json`, `slack`, `discord` | yes | Body shape. `json` is the signed JSON document. `slack` posts `{"text": summary}` and `discord` posts `{"content": summary}` (at most 2,000 characters) for incoming-webhook URLs. Signature headers are sent in every format. |
| `enabled` | boolean | yes | False once the endpoint was disabled, by a failure streak or by `enabled: false`. |
| `disabled_reason` | string \| null | no | Why the endpoint is disabled, when it is. Null while enabled. |
| `consecutive_failures` | integer | yes | Failed deliveries in a row. Reset by a success, and by re-enabling. At 100 the endpoint is disabled. |
| `last_success_at` | string \| null (date-time) | no |  |
| `last_failure_at` | string \| null (date-time) | no |  |
| `secret_version` | integer | yes | Starts at 1 and goes up by one on each rotation. Also the `kid` in signature headers. |
| `created_at` | string (date-time) | yes |  |
| `updated_at` | string (date-time) | yes |  |
| `secret` | string | yes | The HMAC signing key, as a string of the form `whsec_<random>`. Use the whole string, prefix included, as the key bytes. Store it now; it is never returned again. |

#### 400

The request is invalid. Not retryable; fix the request using `code` and `diagnostics.hint`.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 401

Missing, invalid, revoked or expired key. Not retryable with the same key.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 403

The key lacks the scope this route requires (`ERR::AUTH::INSUFFICIENT_SCOPE`), or the action is not permitted.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 409

The organization already has 20 endpoints. Delete one before you add another.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 500

Internal error. Retryable when `retryable` is true.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

Full OpenAPI spec: https://docs.spicrawl.com/openapi.yaml
