---
title: Webhooks
description: >-
  Endpoints HTTPS para link.visit, link.download e link.play, entregues pela
  Svix.
sidebar:
  label: Webhooks
  order: 8
---
Endpoints HTTPS. Apenas HTTPS. Sem localhost nem IPs privados. Até 10 por conta.

Eventos: `link.visit`, `link.download`, `link.play`. O segredo é `whsec_…`, mostrado uma única vez ao criar ou renovar. Guarde-o. Nunca o inclua no corpo JSON.

## CLI

```bash
linkdash webhooks create --url https://example.com/hooks
linkdash webhooks list
linkdash webhooks get <id>
linkdash webhooks rotate <id>
linkdash webhooks delete <id>
```

`list` e `get` devolvem apenas `secretHint` (`whsec_…xxxx`).

## HTTP

```bash
curl https://api.linkdash.dev/v1/webhooks \
  -X POST \
  -H "Authorization: Bearer ldash_..." \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/hooks"}'
```

`GET /webhooks`, `POST /webhooks`, `GET /webhooks/:id`, `DELETE /webhooks/:id`, `POST /webhooks/:id/rotate`.

## Payload

```json
{
  "type": "link.visit",
  "timestamp": "2026-08-17T16:00:00.000Z",
  "data": { "id": "deck", "kind": "file", "variant": "main", "country": "DE", "referrer": "…" }
}
```

`data.variant` é a variante que o visitante recebeu (`main` para ligações com uma única variante).

Cabeçalhos em cada entrega (as repetições do Svix reutilizam o mesmo id):

- `svix-id`
- `svix-timestamp` (segundos Unix)
- `svix-signature` (`v1,<hmac base64>`)

Conteúdo assinado: `{id}.{timestamp}.{corpo bruto}` com HMAC-SHA256. Formato do segredo: `whsec_` + base64.

## Verificar

As entregas são enviadas pela [Svix](https://www.svix.com) e seguem a especificação [Standard Webhooks](https://www.standardwebhooks.com). Verifique com o pacote [`svix`](https://www.npmjs.com/package/svix) (o mesmo usado pela Clerk e pela Resend).

:::note
Passe o corpo **bruto** do pedido a `verify`. Analisar o JSON e voltar a serializá-lo fará falhar a assinatura.
:::

```bash
npm i svix
```

```ts
import { Webhook, WebhookVerificationError } from "svix";

const wh = new Webhook(process.env.LINKDASH_WEBHOOK_SECRET); // whsec_… shown once

try {
  const event = wh.verify(rawBody, {
    "svix-id": headers["svix-id"],
    "svix-timestamp": headers["svix-timestamp"],
    "svix-signature": headers["svix-signature"],
  });
  // event.type is "link.visit" | "link.download" | "link.play"
} catch (err) {
  if (err instanceof WebhookVerificationError) {
    // 400 — do not process
  }
  throw err;
}
```
