---
title: Webhooks
description: >-
  HTTPS-eindpunten voor link.visit, link.download en link.play, afgeleverd door
  Svix.
sidebar:
  label: Webhooks
  order: 8
---
HTTPS-eindpunten. Alleen HTTPS. Geen localhost of privé-IP's. Maximaal 10 per account.

Events: `link.visit`, `link.download`, `link.play`. Het secret is `whsec_…` en wordt één keer getoond bij aanmaken of roteren. Bewaar het goed. Zet het nooit in de JSON-body.

## 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` en `get` geven alleen `secretHint` terug (`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` is de variant die de bezoeker kreeg (`main` voor links met één variant).

Headers bij elke aflevering (Svix-retries hergebruiken dezelfde id):

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

Ondertekende inhoud: `{id}.{timestamp}.{raw body}` met HMAC-SHA256. Secretformaat: `whsec_` + base64.

## Verifiëren

Afleveringen worden verzonden door [Svix](https://www.svix.com) en volgen de [Standard Webhooks](https://www.standardwebhooks.com)-specificatie. Verifieer met het pakket [`svix`](https://www.npmjs.com/package/svix) (zoals bij Clerk en Resend).

:::note
Geef de **ruwe** request body door aan `verify`. Als je de JSON eerst parseert en daarna weer stringify't, faalt de handtekening.
:::

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