# Issue a new signing secret

> Generates a new secret, bumps `secret_version` and sets `secret_rotated_at`.

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

## POST /v1/webhooks/{webhookID}/rotate-secret

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

Generates a new secret, bumps `secret_version` and sets `secret_rotated_at`. The new `secret` is in the
response and is not shown again. The previous secret is kept on the server, but deliveries made after this
call are signed with the new secret only, and carry `kid` equal to the new `secret_version`. Update your
receiver before or as you rotate.

### Example

```bash
curl -X POST "https://api.spicrawl.com/v1/webhooks/{webhookID}/rotate-secret" \
  -H "Authorization: Bearer $SPICRAWL_API_KEY"
```

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `webhookID` | path | string | yes | The endpoint `id`. An id of another organization answers 404. |

### Responses

#### 200

The endpoint with `secret_version` bumped, and the new `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. |

#### 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).

#### 404

No such resource for this key's organization.

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
