# Webhookを作成する

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

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

イベントが起きたら、`GET /events` が返すのと同じオブジェクトを、JSONのPOSTであなたのURLに送ります。10秒以内に2xxのいずれかで応答してください。それ以外は約1日かけて8回再試行し、3日間失敗し続けたエンドポイントは無効になります。同じイベントが2回届くことがあるので、`id` で区別してください。各配信には `Won-Signature: t=<unix time>,v1=<hex>` がつきます。hexは、この呼び出しが返す `signing_secret` で `<t>.<raw body>` を計算したHMAC-SHA256です。シークレットが表示されるのはこの1回だけです。`*` は、高頻度の種類（`email.sent`、`email.opened`、`email.clicked`）を除くすべての種類を意味し、高頻度の種類は名前を挙げたときだけ送られます。Webhookは最大10件です。テストキーで作ったWebhookには、サンドボックスのイベントだけが届きます。無料です。

- **課金：** 無料。

テストキー（`won_test_...`）では、これは[サンドボックス](/ja/docs/email#sandbox)で動きます。何も送信されず、課金もされません。

## パラメーター [#parameters]

パラメーターはJSONのリクエストボディで渡します。

| パラメーター | 型 | 必須 | 説明（APIの原文） |
| --- | --- | --- | --- |
| `url` | string | はい | 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`)[] | いいえ | The types to send, such as `["reply.received", "email.bounced"]`. Default `["*"]`. Default: `*`. |
| `campaign_id` | string | いいえ | Only events of this campaign. |
| `metadata` | object | いいえ | 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. |

## レスポンス [#response]

エラーについては[エラーコード](/ja/docs/errors)を参照してください。

| フィールド | 型 | 説明（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. |

## 例 [#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
  }
}
```