# Rotate the signing secret

POST /v1/webhooks/{webhook_id}/secret/rotate

Source: https://cherami.to/docs/api/webhooks/rotate-webhook-secret



{/* Generated from apps/web/openapi. Edit the contract, not this file. */}

`POST /v1/webhooks/{webhook_id}/secret/rotate`

Requires an [API key](https://cherami.to/docs/api#authentication): `Authorization: Bearer YOUR_CREDENTIAL`.

Creates a new signing secret and returns it. Unless `immediate` is `true`, the replaced secret keeps signing alongside the new one for 24 hours, until `previous_secret_expires_at`, so you can switch your receiver without rejecting deliveries.

Only the replaced secret is affected: a secret from an earlier rotation keeps its own 24-hour expiry, even with `immediate: true`. To stop every earlier secret now, delete the webhook and add it again.

If the response is lost, [read the webhook](https://cherami.to/docs/api/webhooks/get-webhook) before repeating: a new `secret_rotated_at` means the rotation happened, and [retrieving the secret](https://cherami.to/docs/api/webhooks/get-webhook-secret) gives you the new one.

## Parameters [#parameters]

| Parameter    | Location | Required | Type   | Meaning                                  |
| ------------ | -------- | -------- | ------ | ---------------------------------------- |
| `webhook_id` | path     | Yes      | string | Cherami resource ID returned by the API. |

## Request body [#request-body]

JSON object, at most 4 KiB in total.

### Schema: RotateWebhookSecret [#schema-rotatewebhooksecret]

| Field       | Required | Type    | Meaning and constraints                                    |
| ----------- | -------- | ------- | ---------------------------------------------------------- |
| `immediate` | No       | boolean | true stops the replaced secret at once. `default`: `false` |

Unknown fields are rejected.

## curl example [#curl-example]

Supply `CHERAMI_API_KEY` privately.

Save the payload as `request.json`, replacing the example values.

```json
{
  "immediate": false
}
```

```sh
curl --silent --show-error --include --request POST \
  "https://cherami.to/v1/webhooks/WEBHOOK_ID/secret/rotate" \
  --header "Authorization: Bearer $CHERAMI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data-binary @request.json
```

## Responses [#responses]

### HTTP 200 [#http-200]

Success.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[WebhookRotation](#schema-webhookrotation)

```json
{
  "id": "55555555-5555-4555-8555-555555555555",
  "secret": "whsec_EXAMPLE_NOT_A_REAL_SECRET",
  "secret_rotated_at": "2026-10-01T00:00:00.000Z",
  "previous_secret_expires_at": "2026-10-02T00:00:00.000Z"
}
```

### HTTP 400 [#http-400]

`invalid_json`: Send a valid UTF-8 JSON object, not an array or scalar.

`invalid_webhook_rotation`: Send an empty body or only a boolean `immediate`.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

### HTTP 401 [#http-401]

`unauthorized`: Send a valid API key as `Authorization: Bearer <key>`. If the key stopped working, get a new one through [recovery](https://cherami.to/docs/guides/recovery).

* `X-Request-ID`: Identifies this request; include it when reporting a problem.
* `WWW-Authenticate`: `"Bearer"`

Content type: `application/json`.

[Error](#schema-error)

### HTTP 404 [#http-404]

`not_found`: The resource does not exist or does not belong to this account. A reply or forward source must also be in the sending inbox.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

### HTTP 409 [#http-409]

`webhook_operation_in_progress`: Another change to this webhook is in progress. Retry in a minute.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

### HTTP 413 [#http-413]

`body_too_large`: Reduce the JSON request to the operation's body limit.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

### HTTP 415 [#http-415]

`unsupported_media_type`: Send `Content-Type: application/json`.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

### HTTP 503 [#http-503]

`webhook_provider_unavailable`: The request could not be completed, and nothing changed. Retry later.

`webhook_rotation_uncertain`: The rotation was not confirmed and finishes within a few minutes. Then [read the webhook](https://cherami.to/docs/api/webhooks/get-webhook): a new `secret_rotated_at` means it rotated, and [retrieving the secret](https://cherami.to/docs/api/webhooks/get-webhook-secret) gives you the new one.

`webhooks_unavailable`: Webhook management failed. If it was a change, it may have been applied: list or read the webhooks before repeating it.

* `X-Request-ID`: Identifies this request; include it when reporting a problem.

Content type: `application/json`.

[Error](#schema-error)

## Schema: WebhookRotation [#schema-webhookrotation]

| Field                        | Required | Type   | Meaning and constraints                                                                                            |
| ---------------------------- | -------- | ------ | ------------------------------------------------------------------------------------------------------------------ |
| `id`                         | Yes      | string | Cherami resource ID.                                                                                               |
| `secret`                     | Yes      | string | Signing secret for Standard Webhooks verification (whsec\_...). Returned only on creation, retrieval and rotation. |
| `secret_rotated_at`          | Yes      | string | UTC timestamp with milliseconds. `format`: `date-time` `pattern`: `^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$`  |
| `previous_secret_expires_at` | Yes      | string | UTC timestamp with milliseconds. `format`: `date-time` `pattern`: `^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$`  |

## Schema: Error [#schema-error]

| Field   | Required | Type   | Meaning and constraints |
| ------- | -------- | ------ | ----------------------- |
| `error` | Yes      | object |                         |

### `error` fields [#error-fields]

| Field     | Required | Type   | Meaning and constraints                                               |
| --------- | -------- | ------ | --------------------------------------------------------------------- |
| `code`    | Yes      | string | Code to handle. Handle a code you don't recognize by its HTTP status. |
| `message` | Yes      | string | Explanation of this case; its wording can change.                     |

[Errors, limits and pagination](https://cherami.to/docs/api/errors) · [Download OpenAPI 3.1](https://cherami.to/openapi.json)
