> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wepayout.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Update

> Update the URL, events and secret of an existing webhook

# Update Webhook

This endpoint allows updating the URL, the events and the signing secret of a registered webhook.

* The webhook is identified by its `url` and the optional `account_id`, both sent in the request body. The path never carries the URL
* To move the webhook to another address, send the new address in `new_url`
* `events` replaces the whole list: to stop receiving an event on this URL, send the list without it; to start receiving one, add it

> [!WARNING]
>
> Registering, updating or removing a webhook may take up to **5 minutes** to take effect. Until then, webhooks keep being delivered to the previous destination.

## Request Body

**url** `string` *required*

Current URL of the webhook that will be updated. Together with `account_id`, it identifies the webhook. If the account has no webhook with this URL, the request fails with `404`.

Maximum length: 120 characters

Example: `https://my-url.requestcatcher.com/test`

**new\_url** `string`

New endpoint URL for the webhook. When omitted, the URL stays the same.

It must not be registered on another webhook of the account (URLs that differ only in letter case count as the same URL); otherwise the request fails with `422` and the `webhook_url_already_exists` code.

Maximum length: 120 characters

Example: `https://my-url.requestcatcher.com/new`

**events** `string[]` *required*

Complete list of events the webhook will receive after the update. Send at least one event, without repeating any.

Allowed values: `onboarding`, `payin`, `payout`, `kyc`

Each event can be on only one webhook per account: sending an event that another webhook of the account already receives fails with `422` and the `webhook_already_exists` code on that item (for example `events.0`). Remove it from the other webhook first.

Example: `["payin", "payout"]`

**secret** `string`

Secret used to sign the `payin`, `payout` and `kyc` webhooks with [HMAC-SHA256](https://docs.wepayout.co/concepts/webhooks.md#hmac-sha256-signature). When provided, every webhook delivered to this URL includes the `x-webhook-wp-signature` header.

Maximum length: 255 characters. Use a long, randomly generated value.

Example: `whsec_9f8e7d6c5b4a3210`

**account\_id** `integer`

ID of the account whose webhook will be updated: your own merchant or one of its subaccounts.

When omitted, the webhook of **your merchant** (the authenticated account) is updated.

If the account does not exist or is not linked to your merchant, the request fails with `422` and the `invalid_account` code.

Example: `4521`

> [!WARNING]
>
> Without `account_id`, the update always targets **your merchant**, even if the webhook you want to change was listed by [Query](https://docs.wepayout.co/api-reference/account/webhook/webhook-query.md) under a subaccount. Send the `account_id` returned with the webhook to update the right one.

> [!WARNING]
>
> The update replaces the whole configuration. If `secret` is omitted or `null`, the current secret is **removed** and the webhooks are no longer signed. Always send the secret you want to keep.

> [!WARNING]
>
> An event left out of `events` stops being delivered to this URL. On a subaccount, it then goes to the main account's webhook for that event, if there is one — see [Subaccounts without a webhook](https://docs.wepayout.co/api-reference/account/webhook/webhook-setup.md#subaccounts-without-a-webhook).

> [!TIP]
>
> To rotate the secret, send the new value in `secret`. Changes may take up to **5 minutes** to take effect, so accept signatures computed with either the old or the new secret during this period.

## Response

**account\_id** `integer`

ID of the account the webhook belongs to.

Example: `4521`

**events** `string[]`

Events the webhook receives after the update.

Allowed values: `onboarding`, `payin`, `payout`, `kyc`

Example: `["payin", "payout"]`

**url** `string`

Endpoint URL of the webhook after the update

Example: `https://my-url.requestcatcher.com/new`

**secret** `string`

Secret used to sign the webhooks delivered to this URL, or `null` if none is set.

Example: `whsec_9f8e7d6c5b4a3210`

## Request Example

```bash cURL theme={null}
curl --request PUT \
  --url https://api.sandbox.wepayout.com.br/v2/register/companies/webhooks \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer {token}' \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://my-url.requestcatcher.com/test",
    "new_url": "https://my-url.requestcatcher.com/new",
    "events": ["payin", "payout"],
    "secret": "whsec_9f8e7d6c5b4a3210",
    "account_id": 4521
  }'
```

```javascript JavaScript theme={null}
const response = await fetch('https://api.sandbox.wepayout.com.br/v2/register/companies/webhooks', {
  method: 'PUT',
  headers: {
    'Accept': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://my-url.requestcatcher.com/test',
    new_url: 'https://my-url.requestcatcher.com/new',
    events: ['payin', 'payout'],
    secret: 'whsec_9f8e7d6c5b4a3210',
    account_id: 4521
  })
});

const data = await response.json();
console.log(data);
```

```python Python theme={null}
import requests

url = 'https://api.sandbox.wepayout.com.br/v2/register/companies/webhooks'
headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json'
}
data = {
    'url': 'https://my-url.requestcatcher.com/test',
    'new_url': 'https://my-url.requestcatcher.com/new',
    'events': ['payin', 'payout'],
    'secret': 'whsec_9f8e7d6c5b4a3210',
    'account_id': 4521
}

response = requests.put(url, json=data, headers=headers)
print(response.json())
```

```json 200 OK theme={null}
{
  "account_id": 4521,
  "events": ["payin", "payout"],
  "url": "https://my-url.requestcatcher.com/new",
  "secret": "whsec_9f8e7d6c5b4a3210"
}
```

```json 404 Not Found theme={null}
{
  "message": "Webhook not found."
}
```

```json 422 Invalid account theme={null}
{
  "error_code": "validation",
  "error_description": "Validation error",
  "fields": {
    "account_id": ["The account does not exist or is not linked to your merchant."]
  },
  "field_errors": [
    {
      "field": "account_id",
      "code": "invalid_account",
      "params": [],
      "message": "The account does not exist or is not linked to your merchant."
    }
  ]
}
```

```json 422 Event on another webhook theme={null}
{
  "error_code": "validation",
  "error_description": "Validation error",
  "fields": {
    "events.0": ["A webhook for this event already exists for this account."]
  },
  "field_errors": [
    {
      "field": "events.0",
      "code": "webhook_already_exists",
      "params": [],
      "message": "A webhook for this event already exists for this account."
    }
  ]
}
```

```json 422 New URL already registered theme={null}
{
  "error_code": "validation",
  "error_description": "Validation error",
  "fields": {
    "new_url": ["A webhook with this URL already exists for this account."]
  },
  "field_errors": [
    {
      "field": "new_url",
      "code": "webhook_url_already_exists",
      "params": [],
      "message": "A webhook with this URL already exists for this account."
    }
  ]
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.