
# Rotate a webhook endpoint's signing secret

`POST /v1/webhook-endpoints/{endpoint_id}:rotate-secret` · permission `webhook-endpoints:write` · all plans

Issues a new signing secret and returns it once (`Cache-Control: no-store`). During `previous_secret_ttl_hours` (default 24) every delivery carries two signatures in the `webhook-signature` header, one with the old and one with the new secret, so you can switch your receiver without losing deliveries. `0` drops the old secret immediately (for a leaked secret). A request repeated with the same `Idempotency-Key` returns the endpoint without the secret and with `secret_redacted: true`.

## Request

| Field | Type | Required | Description |
|---|---|---|---|
| `endpoint_id` | path | yes | Webhook endpoint ID (`whe_…`). |
| `If-Match` | header | no | When given, must match the endpoint's current `ETag`. |
| `previous_secret_ttl_hours` | integer | no | 0–168 hours the old secret keeps signing; default 24. The body is optional. |
| `Idempotency-Key` | header | no | Replays the response (without the secret) for a repeated request with the same key. |

```json
{
  "previous_secret_ttl_hours": 24
}
```

## Response

`200 OK` with the endpoint, its new `ETag` and the new secret.

```json
{
  "id": "whe_01k8a3m5q7t9v1w3x5y7z9b2c4",
  "key": "crm-sync",
  "url": "https://hooks.example.com/keenauth",
  "description": "CRM sync",
  "event_types": ["user.created", "user.updated"],
  "event_schema_versions": {},
  "payload_mode": "thin",
  "status": "enabled",
  "rate_limit_per_second": 50,
  "previous_secret_expires_at": "2026-10-27T10:00:00Z",
  "last_success_at": "2026-10-26T09:12:00Z",
  "failing_since": null,
  "version": 4,
  "created_at": "2026-10-26T09:00:00Z",
  "updated_at": "2026-10-26T10:00:00Z",
  "signing_secret": "idp_whsec_<secret>"
}
```

## Errors

| HTTP | code | When |
|---|---|---|
| 400 | `unknown_field` | The body has a field that is not listed above. |
| 404 | `not_found` | No such endpoint in this environment. |
| 412 | `precondition_failed` | `If-Match` does not match the current version. |
| 422 | `validation_failed` | `/previous_secret_ttl_hours out_of_range`: not 0–168. |
| 422 | `idempotency_key_reuse` | The `Idempotency-Key` was used with a different request. |
| 401 | `unauthenticated` | The credential is missing, invalid or revoked. |
| 403 | `insufficient_permissions` | The credential lacks `webhook-endpoints:write`. |
| 503 | `service_unavailable` | Webhook administration is temporarily unavailable; retry after the `Retry-After` period. |

## Example

```bash
curl -X POST https://api.eu.keenauth.com/v1/webhook-endpoints/whe_01k8a3m5q7t9v1w3x5y7z9b2c4:rotate-secret \
  -H "Authorization: Bearer $KEENAUTH_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 4c6e8a0b-2d4f-4a6c-9e1b-3d5f7a9c1e3b" \
  -d '{"previous_secret_ttl_hours":24}'
```

CLI: `keenauth webhook-endpoints rotate-secret whe_01k8a3m5q7t9v1w3x5y7z9b2c4 --previous-secret-ttl-hours 24`
