---
title: Webhooks
description: >-
  Endpoints HTTPS para link.visit, link.download y link.play, entregados por
  Svix.
sidebar:
  label: Webhooks
  order: 8
---
Endpoints HTTPS. Solo HTTPS. No se permiten localhost ni IPs privadas. Hasta 10 por cuenta.

Eventos: `link.visit`, `link.download`, `link.play`. El secreto es `whsec_…` y se muestra una sola vez al crearlo o rotarlo. Guárdalo. Nunca lo pongas en el cuerpo 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` y `get` solo devuelven `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` es la variante que recibió el visitante (`main` para links de una sola variante).

Headers en cada entrega (los reintentos de Svix reutilizan el mismo id):

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

Contenido firmado: `{id}.{timestamp}.{raw body}` con HMAC-SHA256. Formato del secreto: `whsec_` + base64.

## Verificación

Las entregas las envía [Svix](https://www.svix.com) y siguen la especificación [Standard Webhooks](https://www.standardwebhooks.com). Verifícalas con el paquete [`svix`](https://www.npmjs.com/package/svix) (el mismo que usan Clerk y Resend).

:::note
Pásale a `verify` el cuerpo **sin procesar** de la solicitud. Si parseas el JSON y lo vuelves a convertir en string, la verificación de la firma va a fallar.
:::

```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;
}
```
