# Rotate a webhook secret

> **POST** `https://api.us.nylas.com/v3/webhooks/rotate-secret/{id}`

Source: https://developer.nylas.com/docs/reference/api/webhook-notifications/post-new-secret/

Update the webhook secret value for a destination. The previous value will immediately stop being used and the new value will take over.

### Webhook notification header

Every webhook notification Nylas sends includes the `x-nylas-signature` header. Depending on the SDK you're using, you might see `X-Nylas-Signature` instead.

**Authentication:** NYLAS_API_KEY

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | Yes |  |

## Responses

### 200 - Returns the updated Destination.

- `data` (object)
  - `id` (string) - A unique identifier for the webhook destination.
  - `description` (string) - A human-readable description of the webhook destination.
  - `trigger_types` (array) - The event that triggers the notification. See the
[notification schemas](/docs/reference/notifications/) for details about each trigger
type.

See the [Grants](/docs/reference/api/manage-grants/), [Calendar](/docs/reference/api/calendar/),
[Events](/docs/reference/api/events/), and [Messages](/docs/reference/api/messages/) references
for information on how to trigger each event type.
  - `webhook_url` (string) - The URL to send webhooks to.
  - `webhook_secret` (string) - A secret value used to encode the `x-nylas-signature` header on webhook requests.
  - `status` (string) - The status of the new destination.
  - `notification_email_addresses` (array) - The email addresses that Nylas notifies when a webhook is down for a while. See
[Failing and failed webhooks](/docs/v3/notifications/#failing-and-failed-webhooks) for
details.
- `request_id` (string) - The request ID for each request.

### 400 - Notification channel not deleted

- `error` (object)
  - `type` (string) - An alphanumeric code that represents the error type.
  - `message` (string) - A human readable message with details about the error.
- `request_id` (string) - The unique ID of the request that generated this response.

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.us.nylas.com/v3/webhooks/rotate-secret/<WEBHOOK_ID>' \  
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

const nylas = new Nylas({
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
});

const rotated = await nylas.webhooks.rotateSecret({
  webhookId: "<WEBHOOK_ID>",
});

console.log("Rotated webhook secret:", rotated);

```

### Python SDK

```python
from nylas import Client

nylas = Client(
    "<NYLAS_API_KEY>",
    "<NYLAS_API_URI>",
)

webhook = nylas.webhooks.rotate_secret(
    "<WEBHOOK_ID>"
)

print(webhook)

```

### Ruby SDK

```ruby
# frozen_string_literal: true

# Load gems
require 'nylas'

# Initialize Nylas client
nylas = Nylas::Client.new(
    api_key: '<NYLAS_API_KEY>'
)

secret, _ = nylas.webhooks.rotate_secret(webhook_id: "<WEBHOOK_ID>")

puts secret

```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.*;
import java.util.List;

public class read_grants {
  public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError {
    NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();
    Response<WebhookWithSecret> secret = nylas.webhooks().rotateSecret("<WEBHOOK_ID>");
    
    System.out.println(secret);
  }
}

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient
import com.nylas.models.UpdateGrantRequest

fun main(args: Array<String>) {
  val nylas: NylasClient = NylasClient(
      apiKey = "<NYLAS_API_KEY>"
  )

  val secret = nylas.webhooks().rotateSecret("<WEBHOOK_ID>")
  
  print(secret)
}

```
