<!-- Fonte: https://docs.onzepay.com/api/webhooks -->
# Endpoints de webhook

Cadastre as URLs que recebem eventos. O [guia de webhooks](/webhooks) explica o payload, a assinatura e os reenvios.

## Cadastrar um endpoint

`POST https://api.onzepay.com/v1/webhooks/endpoints`

Escopo: `webhooks.write` · exige `Idempotency-Key`.

**Corpo**

| Campo | Tipo | Descrição |
|---|---|---|
| `url` *(obrigatório)* | string | URL HTTPS que recebe o POST. |
| `events` *(obrigatório)* | array | Eventos assinados (ao menos um). |
| `errorNotificationEmail` *(obrigatório)* | string | E-mail de contato técnico do endpoint. |
| `autoPauseOnFailure` | boolean | Pausa o endpoint depois de falhas seguidas. Padrão `true`. |
| `isPaused` | boolean | Cria já pausado. |
| `headers` | array | Headers extras `{ key, value }` enviados em cada entrega. |

:::tabs
```bash title="curl"
curl -X POST "$ONZEPAY_API/v1/webhooks/endpoints" \
  -H "Authorization: Bearer $ONZEPAY_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "url": "https://seu-sistema.com.br/webhooks/onzepay",
  "events": [
    "charge.paid",
    "charge.expired",
    "pix.refund.failed",
    "med.opened",
    "med.updated"
  ],
  "errorNotificationEmail": "dev@seu-sistema.com.br"
}'
```
```javascript title="Node.js"
const res = await fetch(`${process.env.ONZEPAY_API}/v1/webhooks/endpoints`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ONZEPAY_SECRET_KEY}`,
    'Idempotency-Key': crypto.randomUUID(),
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "url": "https://seu-sistema.com.br/webhooks/onzepay",
    "events": [
      "charge.paid",
      "charge.expired",
      "pix.refund.failed",
      "med.opened",
      "med.updated"
    ],
    "errorNotificationEmail": "dev@seu-sistema.com.br"
  })
})
const data = await res.json()
if (!res.ok) throw new Error(`${data.code}: ${data.message}`)
```
```python title="Python"
import os, uuid
import requests

res = requests.post(
    f"{os.environ['ONZEPAY_API']}/v1/webhooks/endpoints",
    headers={"Authorization": f"Bearer {os.environ['ONZEPAY_SECRET_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
        "url": "https://seu-sistema.com.br/webhooks/onzepay",
        "events": ["charge.paid", "charge.expired", "pix.refund.failed", "med.opened", "med.updated"],
        "errorNotificationEmail": "dev@seu-sistema.com.br",
    },
    timeout=30,
)
res.raise_for_status()
data = res.json()
```
:::

**Resposta `201`**

```json
{
  "id": "whk_034yDL6mN8bV0cX2zL4kJ6",
  "url": "https://seu-sistema.com.br/webhooks/onzepay",
  "events": [
    "charge.paid",
    "charge.expired",
    "pix.refund.failed",
    "med.opened",
    "med.updated"
  ],
  "errorNotificationEmail": "dev@seu-sistema.com.br",
  "autoPauseOnFailure": true,
  "isPaused": false,
  "status": "active",
  "createdAt": "2026-11-15T20:00:00.000Z",
  "updatedAt": "2026-11-15T20:00:00.000Z"
}
```

**Erros**

| HTTP | `code` | Quando |
|---|---|---|
| `400` | `EVENTS_REQUIRED` | Nenhum evento informado. |

## Listar endpoints

`GET https://api.onzepay.com/v1/webhooks/endpoints`

Escopo: `webhooks.read`.

:::tabs
```bash title="curl"
curl -X GET "$ONZEPAY_API/v1/webhooks/endpoints" \
  -H "Authorization: Bearer $ONZEPAY_SECRET_KEY"
```
```javascript title="Node.js"
const res = await fetch(`${process.env.ONZEPAY_API}/v1/webhooks/endpoints`, {
  method: 'GET',
  headers: {
    Authorization: `Bearer ${process.env.ONZEPAY_SECRET_KEY}`
  }
})
const data = await res.json()
if (!res.ok) throw new Error(`${data.code}: ${data.message}`)
```
```python title="Python"
import os
import requests

res = requests.get(
    f"{os.environ['ONZEPAY_API']}/v1/webhooks/endpoints",
    headers={"Authorization": f"Bearer {os.environ['ONZEPAY_SECRET_KEY']}"},
    timeout=30,
)
res.raise_for_status()
data = res.json()
```
:::

**Resposta `200`**

```json
{
  "data": [
    {
      "id": "whk_034yDL6mN8bV0cX2zL4kJ6",
      "url": "https://seu-sistema.com.br/webhooks/onzepay",
      "events": [
        "charge.paid",
        "charge.expired",
        "pix.refund.failed",
        "med.opened",
        "med.updated"
      ],
      "errorNotificationEmail": "dev@seu-sistema.com.br",
      "autoPauseOnFailure": true,
      "isPaused": false,
      "status": "active",
      "createdAt": "2026-11-15T20:00:00.000Z",
      "updatedAt": "2026-11-15T20:00:00.000Z"
    }
  ]
}
```

## Consultar um endpoint

`GET https://api.onzepay.com/v1/webhooks/endpoints/{id}`

Escopo: `webhooks.read`.

**Parâmetros de caminho**

| Campo | Tipo | Descrição |
|---|---|---|
| `id` *(obrigatório)* | string | Id do endpoint (`whk_…`). |

:::tabs
```bash title="curl"
curl -X GET "$ONZEPAY_API/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6" \
  -H "Authorization: Bearer $ONZEPAY_SECRET_KEY"
```
```javascript title="Node.js"
const res = await fetch(`${process.env.ONZEPAY_API}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6`, {
  method: 'GET',
  headers: {
    Authorization: `Bearer ${process.env.ONZEPAY_SECRET_KEY}`
  }
})
const data = await res.json()
if (!res.ok) throw new Error(`${data.code}: ${data.message}`)
```
```python title="Python"
import os
import requests

res = requests.get(
    f"{os.environ['ONZEPAY_API']}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6",
    headers={"Authorization": f"Bearer {os.environ['ONZEPAY_SECRET_KEY']}"},
    timeout=30,
)
res.raise_for_status()
data = res.json()
```
:::

**Resposta `200`**

```json
{
  "id": "whk_034yDL6mN8bV0cX2zL4kJ6",
  "url": "https://seu-sistema.com.br/webhooks/onzepay",
  "events": [
    "charge.paid",
    "charge.expired",
    "pix.refund.failed",
    "med.opened",
    "med.updated"
  ],
  "errorNotificationEmail": "dev@seu-sistema.com.br",
  "autoPauseOnFailure": true,
  "isPaused": false,
  "status": "active",
  "createdAt": "2026-11-15T20:00:00.000Z",
  "updatedAt": "2026-11-15T20:00:00.000Z"
}
```

## Alterar um endpoint

`PATCH https://api.onzepay.com/v1/webhooks/endpoints/{id}`

Escopo: `webhooks.write`.

Envie só os campos que mudam. `isPaused: false` reativa um endpoint pausado.

**Parâmetros de caminho**

| Campo | Tipo | Descrição |
|---|---|---|
| `id` *(obrigatório)* | string | Id do endpoint (`whk_…`). |

:::tabs
```bash title="curl"
curl -X PATCH "$ONZEPAY_API/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6" \
  -H "Authorization: Bearer $ONZEPAY_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "isPaused": false,
  "events": [
    "pix.in.received",
    "pix.refund.completed",
    "pix.refund.failed"
  ]
}'
```
```javascript title="Node.js"
const res = await fetch(`${process.env.ONZEPAY_API}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6`, {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${process.env.ONZEPAY_SECRET_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "isPaused": false,
    "events": [
      "pix.in.received",
      "pix.refund.completed",
      "pix.refund.failed"
    ]
  })
})
const data = await res.json()
if (!res.ok) throw new Error(`${data.code}: ${data.message}`)
```
```python title="Python"
import os
import requests

res = requests.patch(
    f"{os.environ['ONZEPAY_API']}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6",
    headers={"Authorization": f"Bearer {os.environ['ONZEPAY_SECRET_KEY']}"},
    json={
        "isPaused": False,
        "events": ["pix.in.received", "pix.refund.completed", "pix.refund.failed"],
    },
    timeout=30,
)
res.raise_for_status()
data = res.json()
```
:::

**Resposta `200`**

```json
{
  "id": "whk_034yDL6mN8bV0cX2zL4kJ6",
  "url": "https://seu-sistema.com.br/webhooks/onzepay",
  "events": [
    "pix.in.received",
    "pix.refund.completed",
    "pix.refund.failed"
  ],
  "errorNotificationEmail": "dev@seu-sistema.com.br",
  "autoPauseOnFailure": true,
  "isPaused": false,
  "status": "active",
  "createdAt": "2026-11-15T20:00:00.000Z",
  "updatedAt": "2026-11-15T20:00:00.000Z"
}
```

## Remover um endpoint

`DELETE https://api.onzepay.com/v1/webhooks/endpoints/{id}`

Escopo: `webhooks.write`.

**Parâmetros de caminho**

| Campo | Tipo | Descrição |
|---|---|---|
| `id` *(obrigatório)* | string | Id do endpoint (`whk_…`). |

:::tabs
```bash title="curl"
curl -X DELETE "$ONZEPAY_API/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6" \
  -H "Authorization: Bearer $ONZEPAY_SECRET_KEY"
```
```javascript title="Node.js"
const res = await fetch(`${process.env.ONZEPAY_API}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6`, {
  method: 'DELETE',
  headers: {
    Authorization: `Bearer ${process.env.ONZEPAY_SECRET_KEY}`
  }
})
if (!res.ok) throw new Error(`HTTP ${res.status}`)
```
```python title="Python"
import os
import requests

res = requests.delete(
    f"{os.environ['ONZEPAY_API']}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6",
    headers={"Authorization": f"Bearer {os.environ['ONZEPAY_SECRET_KEY']}"},
    timeout=30,
)
res.raise_for_status()
```
:::

**Resposta `204`**: sem corpo.

## Enviar evento de teste

`POST https://api.onzepay.com/v1/webhooks/endpoints/{id}/test`

Escopo: `webhooks.write`.

Envia um `webhook.test` assinado para a URL e devolve o status HTTP que ela respondeu. Limite próprio: 10 por minuto.

**Parâmetros de caminho**

| Campo | Tipo | Descrição |
|---|---|---|
| `id` *(obrigatório)* | string | Id do endpoint (`whk_…`). |

:::tabs
```bash title="curl"
curl -X POST "$ONZEPAY_API/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6/test" \
  -H "Authorization: Bearer $ONZEPAY_SECRET_KEY"
```
```javascript title="Node.js"
const res = await fetch(`${process.env.ONZEPAY_API}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6/test`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ONZEPAY_SECRET_KEY}`
  }
})
const data = await res.json()
if (!res.ok) throw new Error(`${data.code}: ${data.message}`)
```
```python title="Python"
import os
import requests

res = requests.post(
    f"{os.environ['ONZEPAY_API']}/v1/webhooks/endpoints/whk_034yDL6mN8bV0cX2zL4kJ6/test",
    headers={"Authorization": f"Bearer {os.environ['ONZEPAY_SECRET_KEY']}"},
    timeout=30,
)
res.raise_for_status()
data = res.json()
```
:::

**Resposta `200`**

```json
{
  "delivered": true,
  "status": 200,
  "body": "ok"
}
```

**Erros**

| HTTP | `code` | Quando |
|---|---|---|
| `400` | `WEBHOOK_TEST_FAILED` | A URL não respondeu (DNS, TLS ou tempo esgotado). |

## Reenviar uma entrega

`POST https://api.onzepay.com/v1/webhooks/deliveries/{id}/retry`

Escopo: `webhooks.write`.

Coloca a entrega (`evt_…`, o mesmo `id` do evento recebido) de volta na fila.

**Parâmetros de caminho**

| Campo | Tipo | Descrição |
|---|---|---|
| `id` *(obrigatório)* | string | Id do evento (`evt_…`). |

:::tabs
```bash title="curl"
curl -X POST "$ONZEPAY_API/v1/webhooks/deliveries/evt_034yDL8pA1sD3fG5hJ7kL9/retry" \
  -H "Authorization: Bearer $ONZEPAY_SECRET_KEY"
```
```javascript title="Node.js"
const res = await fetch(`${process.env.ONZEPAY_API}/v1/webhooks/deliveries/evt_034yDL8pA1sD3fG5hJ7kL9/retry`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ONZEPAY_SECRET_KEY}`
  }
})
const data = await res.json()
if (!res.ok) throw new Error(`${data.code}: ${data.message}`)
```
```python title="Python"
import os
import requests

res = requests.post(
    f"{os.environ['ONZEPAY_API']}/v1/webhooks/deliveries/evt_034yDL8pA1sD3fG5hJ7kL9/retry",
    headers={"Authorization": f"Bearer {os.environ['ONZEPAY_SECRET_KEY']}"},
    timeout=30,
)
res.raise_for_status()
data = res.json()
```
:::

**Resposta `200`**

```json
{
  "id": "evt_034yDL8pA1sD3fG5hJ7kL9",
  "type": "charge.paid",
  "status": "queued",
  "attemptCount": 2,
  "createdAt": "2026-11-15T21:05:01.000Z",
  "updatedAt": "2026-11-15T21:40:00.000Z"
}
```

**Erros**

| HTTP | `code` | Quando |
|---|---|---|
| `409` | `IDEMPOTENCY_CONFLICT` | Esta entrega já foi concluída. |
