---
title: Webhook
description: Svix によって配信される link.visit、link.download、link.play 用の HTTPS エンドポイントです。
sidebar:
  label: Webhook
  order: 8
---
HTTPS エンドポイントです。HTTPS のみ対応しています。localhost やプライベート IP は使用できません。1 アカウントあたり最大 10 個まで登録できます。

イベントは `link.visit`、`link.download`、`link.play` です。シークレットは `whsec_…` 形式で、作成時およびローテーション時に一度だけ表示されます。必ず保管してください。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` と `get` は `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`。

## ペイロード

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

`data.variant` は訪問者に提供されたバリアントです（単一バリアントのリンクでは `main`）。

すべての配信に付与されるヘッダーは次のとおりです（Svix による再試行では同じ id が再利用されます）。

- `svix-id`
- `svix-timestamp`（Unix 秒）
- `svix-signature`（`v1,<base64 hmac>`）

署名対象は `{id}.{timestamp}.{raw body}` で、HMAC-SHA256 で署名されます。シークレットの形式は `whsec_` + base64 です。

## 検証

配信は [Svix](https://www.svix.com) によって行われ、[Standard Webhooks](https://www.standardwebhooks.com) 仕様に準拠しています。[`svix`](https://www.npmjs.com/package/svix) パッケージ（Clerk や Resend と同じもの）を使って検証してください。

:::note
`verify` には**生の**リクエストボディを渡してください。JSON をパースしてから再度文字列化すると、署名の検証に失敗します。
:::

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