# Rotate the signing secret

POST /v1/webhook-endpoints/{endpointId}/rotate-secret. Replaces the endpoint's signing secret and returns the new one, the only time it is returned.

`POST https://api.chatwise.so/v1/webhook-endpoints/{endpointId}/rotate-secret`

Replaces the endpoint's signing secret and returns the new one, the only time it is returned. For 24 hours every delivery carries two signatures, made with the new secret and the previous one, so you can switch without missing any.

The API key needs the `webhooks:write` scope. It also needs `messages:read` when the endpoint has `message.*` events. See [authentication and scopes](https://chatwise.so/docs/authentication.md).

## Example

**curl**:

```bash
curl -X POST 'https://api.chatwise.so/v1/webhook-endpoints/we_01JE2Z3K8Q9V7W5X4Y3Z2A1B0C/rotate-secret' \
  -H "Authorization: Bearer $CHATWISE_API_KEY"
```

**Node.js**:

```js
const response = await fetch("https://api.chatwise.so/v1/webhook-endpoints/we_01JE2Z3K8Q9V7W5X4Y3Z2A1B0C/rotate-secret", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CHATWISE_API_KEY}`,
  },
});
const body = await response.json();
if (!response.ok) throw new Error(`${response.status}: ${body.message}`);
console.log(body.data);
```

**Python**:

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://api.chatwise.so/v1/webhook-endpoints/we_01JE2Z3K8Q9V7W5X4Y3Z2A1B0C/rotate-secret",
    method="POST",
    headers={
        "Authorization": f"Bearer {os.environ['CHATWISE_API_KEY']}",
    },
)
with urllib.request.urlopen(request) as response:
    print(json.load(response)["data"])
```

## Path parameters

| Name | Type | Description |
| --- | --- | --- |
| `endpointId` | string | **Required.** The endpoint's id (`we_…`). |

## Response

**200.** The new secret.

```json
{
  "data": {
    "signingSecret": "whsec_ZXhhbXBsZS1zZWNyZXQtZG8tbm90LXVzZS0wMDAwMDA=",
    "previousSecretExpiresAt": "2026-12-01T10:00:00.000Z"
  }
}
```

| Field | Type | Description |
| --- | --- | --- |
| `data.signingSecret` | string | The secret that signs its deliveries: `whsec_` and 32 random bytes in base64. Shown only here; store it safely. |
| `data.previousSecretExpiresAt` | string | Until when deliveries are signed with the previous secret too. ISO 8601, in UTC. |

## Errors

| Status | Message | What it means |
| --- | --- | --- |
| 400 | Validation failed | A parameter or body field is missing, unknown or malformed. `errors` lists each one. |
| 401 | A valid Bearer API key is required | The `Authorization` header is missing or isn't `Bearer <API key>`. |
| 401 | Invalid or revoked API key | The key doesn't exist, was revoked, or has expired. |
| 401 | Invalid API key | Chatwise couldn't check the key. Try again. |
| 403 | API key does not have the required scope: webhooks:write | The key lacks the route's scope. Create a key that has it. |
| 403 | Changing an endpoint that receives message events needs an API key with the messages:read scope too. | The endpoint has `message.*` events and the key lacks `messages:read`. |
| 404 | Webhook endpoint not found | No endpoint with this id in the key's workspace. |
| 429 | API key rate limit exceeded | Wait the number of seconds in the `Retry-After` header. |
| 500 | Internal server error | Something failed in Chatwise. Retry reads with backoff. |

The body of an error is described in [errors](https://chatwise.so/docs/errors.md).
