# Rotate a webhook endpoint's secret

`POST https://api.morevoice.ai/v1/webhook_endpoints/{id}/rotate_secret`

Creates a new signing secret and returns it (this once). The previous secret keeps signing alongside it for `expire_previous_in_hours` (default 24), so `webhook-signature` carries both signatures until your receivers switch. An `ed25519` endpoint gets a new key pair instead: the response carries the new `public_key` and the previous one (no secret). `signing` switches the scheme with the same overlap.

Authenticate with a secret API key: `Authorization: Bearer $MOREVOICE_API_KEY`.

Operation ID: `webhook_endpoints_rotate_secret`.

## Parameters

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | A webhook endpoint ID (`we_…`). |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `MoreVoice-Version` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `Idempotency-Key` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |

## Request body

Optional, `application/json`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `expire_previous_in_hours` | `number` | no | How long the previous secret keeps signing alongside the new one (0–72 hours, default 24; 0 stops it at once). |
| `signing` | `"hmac" \| "ed25519"` | no | Switch the scheme with this rotation (default: keep the endpoint's). During the overlap `webhook-signature` carries both a `v1` and a `v1a` entry, so receivers can move over without missing an event. |

Example:

```json
{
  "expire_previous_in_hours": 24
}
```

## Responses

### 200 OK

OK Returns `WebhookEndpoint`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | A webhook endpoint ID (prefix `we_`). |
| `object` | `"webhook_endpoint"` | — |
| `url` | `string` | Where events are POSTed. |
| `description` | `string` | — |
| `enabled_events` | `string[]` | The event types sent to this endpoint; `["*"]` means every event. |
| `status` | `"enabled" \| "disabled" \| "auto_disabled"` | `auto_disabled`: every delivery failed for 72 hours, so sending stopped (and your admins were told). Set `status: enabled` to resume. |
| `disabled_reason` | `string \| null` | — |
| `disabled_at` | `string \| null` | — |
| `api_version` | `string` | The API version event payloads are rendered in. `legacy`: an endpoint moved from the old webhook settings, which keeps getting the previous body (`{id, event, createdAt, data}`). |
| `campaign_id` | `string \| null` | `cmp_…` ID. |
| `legacy_headers` | `boolean` | Also sends the previous `X-Webhook-*` headers (moved endpoints, for one deprecation cycle). |
| `max_in_flight` | `integer` | Deliveries in flight to this endpoint at once; more wait their turn. |
| `metadata` | `Metadata` | Up to 50 key/value pairs (keys up to 40 characters, values up to 500) you attach to an object. Returned as sent. |
| `previous_secret_expires_at` | `string \| null` | While a rotated secret still signs (alongside the new one): until when. |
| `signing` | `"hmac" \| "ed25519"` | How deliveries are signed (Standard Webhooks). `hmac` (default): `v1,<HMAC-SHA256>` with a shared secret (`whsec_…`) returned once. `ed25519`: `v1a,<Ed25519 signature>`; you verify with the endpoint's `public_key` (`whpk_…`) and no secret is ever shared. |
| `public_key` | `string \| null` | `ed25519` endpoints: the Ed25519 public key (`whpk_` + base64 of 32 bytes) that verifies `v1a` signatures; also as PEM at `GET /v1/webhook_endpoints/{id}/public_key`. Null for `hmac`. |
| `previous_public_key` | `string \| null` | After a rotation of an `ed25519` key: the previous public key, which still signs alongside until `previous_secret_expires_at`. |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `created` | `string` | An ISO-8601 timestamp in UTC. |
| `updated` | `string` | An ISO-8601 timestamp in UTC. |
| `secret` | `string` | The signing secret (`whsec_…`) of an `hmac` endpoint. Returned only when the endpoint is created and when its secret is rotated: store it then. `ed25519` endpoints never return one. |

Example:

```json
{
  "api_version": "2026-11-01",
  "campaign_id": null,
  "created": "2026-11-03T09:14:22.000Z",
  "description": "CRM sync",
  "disabled_at": null,
  "disabled_reason": null,
  "enabled_events": [
    "call.ended",
    "call.analyzed"
  ],
  "id": "we_4Gk2LmN9pQ4rS6tV8wX0yZ",
  "legacy_headers": false,
  "livemode": true,
  "max_in_flight": 10,
  "metadata": {},
  "object": "webhook_endpoint",
  "previous_public_key": null,
  "previous_secret_expires_at": null,
  "public_key": null,
  "signing": "hmac",
  "status": "enabled",
  "updated": "2026-11-03T09:14:22.000Z",
  "url": "https://hooks.example.com/webhooks"
}
```

### 400 Bad Request

The request is invalid: a parameter is missing, malformed or unknown, or the version header is unknown. Returns `ErrorEnvelope`.

### 401 Unauthorized

No valid API key was sent. Returns `ErrorEnvelope`.

### 403 Forbidden

The key may not do this (a missing scope, a plan limit, or a compliance block). Returns `ErrorEnvelope`.

### 404 Not Found

No object with this ID (in the path or the body) exists in this organisation and mode. Returns `ErrorEnvelope`.

### 409 Conflict

The request conflicts with the object's state, or the Idempotency-Key was reused with other parameters. Returns `ErrorEnvelope`.

### 413 Payload Too Large

The request body is larger than the endpoint accepts, or has more parts or files than it takes. Returns `ErrorEnvelope`.

### 415 Unsupported Media Type

The request body's Content-Type is not one the endpoint takes. Returns `ErrorEnvelope`.

### 429 Too Many Requests

Too many requests, or no call capacity right now. Retry after the Retry-After delay. Returns `ErrorEnvelope`.

### 500 Internal Server Error

Something went wrong on MoreVoice's side. Retry with the same Idempotency-Key. Returns `ErrorEnvelope`.

## Code samples

**TypeScript**

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const webhookEndpoint = await mv.webhookEndpoints.rotateSecret("we_7Hk2Lm9Qp", {
	expire_previous_in_hours: 24,
});
console.log(webhookEndpoint);
```

**Python**

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

webhook_endpoint = client.webhook_endpoints.rotate_secret("we_7Hk2Lm9Qp", {
    "expire_previous_in_hours": 24,
})
print(webhook_endpoint)
```

**cURL**

```sh
curl -X POST https://api.morevoice.ai/v1/webhook_endpoints/we_7Hk2Lm9Qp/rotate_secret \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "expire_previous_in_hours": 24
}'
```
