# Criar um webhook

Source: https://won.dev/pt-BR/docs/email/webhooks-create

`POST https://api.won.dev/v1/webhooks`

Envia os eventos para uma URL sua conforme eles acontecem, como um POST JSON com o mesmo objeto que `GET /events` retorna. Responda com qualquer 2xx em até 10 segundos; qualquer outra coisa é tentada de novo, oito vezes ao longo de cerca de um dia, e um endpoint que falha por três dias é desativado. O mesmo evento pode chegar duas vezes: diferencie pelo `id`. Cada entrega traz `Won-Signature: t=<unix time>,v1=<hex>`, em que o hex é o HMAC-SHA256 de `<t>.<raw body>` com o `signing_secret` que esta chamada retorna. O segredo é mostrado só desta vez. `*` significa todos os tipos, exceto os frequentes (`email.sent`, `email.opened`, `email.clicked`), que só são enviados quando nomeados. Até 10 webhooks. Um webhook criado com uma chave de teste recebe os eventos do sandbox, e só eles. Grátis.

- **Cobrança:** Grátis.

Uma chave de teste (`won_test_...`) roda isto no [sandbox](/pt-BR/docs/email#sandbox): nada é enviado e nada é cobrado.

## Parâmetros [#parameters]

Os parâmetros vão no corpo JSON.

| Parâmetro | Tipo | Obrigatório | Descrição (texto original da API) |
| --- | --- | --- | --- |
| `url` | string | sim | Where to send events: an `https://` URL that is reachable from the internet. |
| `events` | (`*` \| `sender.approved` \| `sender.rejected` \| `sender.suspended` \| `domain.ready` \| `domain.failed` \| `domain.renewal_upcoming` \| `domain.renewal_failed` \| `domain.released` \| `campaign.started` \| `campaign.paused` \| `campaign.resumed` \| `campaign.completed` \| `campaign.canceled` \| `email.sent` \| `email.opened` \| `email.clicked` \| `email.bounced` \| `reply.received` \| `recipient.unsubscribed` \| `task.completed`)[] | não | The types to send, such as `["reply.received", "email.bounced"]`. Default `["*"]`. Default: `*`. |
| `campaign_id` | string | não | Only events of this campaign. |
| `metadata` | object | não | Your own keys and values, such as `{"customer_id": "c_812"}`: up to 20 keys of at most 40 characters, each value a string of at most 500. Returned with the webhook. Events do not carry it: the same event goes to every webhook. |

## Resposta [#response]

Os erros estão descritos em [Erros](/pt-BR/docs/errors).

| Campo | Tipo | Descrição (texto original da API) |
| --- | --- | --- |
| `data` | object | The webhook, with the secret its deliveries are signed with. |
| `data.id` | string | Webhook ID, such as `whk_2m9x7p1q8w3e5r4k`. |
| `data.url` | string |  |
| `data.events` | string[] |  |
| `data.campaign_id` | string \| null |  |
| `data.status` | `enabled` \| `disabled` |  |
| `data.disabled_reason` | string \| null |  |
| `data.metadata` | object | Your own keys and values, as you gave them. Empty when none were. |
| `data.created_at` | string | When it was created, as an ISO 8601 time in UTC. |
| `data.signing_secret` | string | The key deliveries are signed with. Store it now: it is not shown again. |
| `notice` | string \| null | A plain sentence when there is something to know about this answer. Null otherwise. |
| `usage` | object | Nothing is charged here. The balance, for reference. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

## Exemplo [#example]

```bash
curl https://api.won.dev/v1/webhooks \
  -H "Authorization: Bearer $WON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "url": "https://agent.example/hooks/won",
  "events": [
    "reply.received",
    "email.bounced"
  ]
}'
```

```json
{
  "data": {
    "id": "whk_2m9x7p1q8w3e5r4k",
    "url": "https://agent.example/hooks/won",
    "events": [
      "reply.received",
      "email.bounced"
    ],
    "campaign_id": null,
    "status": "enabled",
    "disabled_reason": null,
    "metadata": {},
    "created_at": "2026-11-18T13:58:00.000Z",
    "signing_secret": "whsec_4Zb1rW8sQ0nT7vYcK3mL9xDfH2gJ6pA5"
  },
  "notice": null,
  "usage": {
    "cost": 0,
    "balance": 48.08,
    "replayed": false
  }
}
```