# Webhooks and the event log

> Zurchin tells your server when something concerns you: mail arrives, is held or bounces, a domain is proved, a key or a member changes. Each delivery is signed with your endpoint’s secret. Everything that happens in the account is also kept in an event log you can read with `GET /v1/events`.

Source: https://zurchin.com/docs/webhooks

## Events you can subscribe to

### Email’s events

Each is sent with the same `data` the [event log](#event-log) keeps for it, to the account’s endpoints that asked for it.

| `type` | When |
| --- | --- |
| `message.received` | Mail reached an inbox. `inbox_id`, `message_id`, `thread_id`, `from`, `subject`, `rfc_message_id`, `spam`, `firewall`, and `test: true` on test mail. An `events` inbox keeps no mail: no `message_id` or `thread_id`, and `text` instead. |
| `message.held` | The Firewall held mail for a person: ids and the verdict, never the subject or body; `release_url`. Or, with `reason: "flagged"`, a send of a flagged account waits for a person at Zurchin: `message_id`, `inbox_id`. |
| `message.released` | A person released held mail. |
| `message.blocked`, `message.quarantined` | Mail not delivered: a receive rule, or a virus. |
| `message.sent`, `message.failed`, `message.scheduled` | What became of a send. |
| `message.delivered`, `message.delayed`, `message.bounced`, `message.complained`, `message.rejected` | What the receiving servers said, per recipient. |
| `message.exfiltration_blocked` | A send was refused for text a key read in another conversation. |
| `draft.created`, `draft.approval_requested`, `draft.approved`, `draft.rejected` | Drafts and approval; `approve_url` on a request. |
| `thread.updated`, `thread.deleted` | A conversation filed, handed over or deleted. |
| `inbox.created`, `inbox.updated`, `inbox.removed` | Inboxes. |
| `email.domain_added`, `email.domain_verified`, `email.domain_broken`, `email.domain_removed` | Mail on your own domain; `broken` when mail was arriving and the MX no longer points here. |
| `calendar.event.created`, `calendar.event.updated`, `calendar.event.deleted` | The calendar, from the API or a calendar app. |

## Add an endpoint

Under **Settings → Webhooks**, or through the API, for any event. Give a public `https://` address and the events; the secret (`whsec_…`) is shown once. An address on a private network is refused, by its name or by the addresses its DNS answers, and a delivery never follows a redirect.

curl:

```bash
curl https://zurchin.com/v1/webhooks \
  -H "Authorization: Bearer $ZURCHIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/pidgeon", "events": ["message.received", "message.bounced"]}'
```

Response 201:

```json
{ "id": "8d7c6b5a-4f3e-4d2c-9b1a-0f9e8d7c6b5a", "secret": "whsec_…" }
```

| Call | Access | Answers |
| --- | --- | --- |
| `GET /v1/webhooks` | `read` | `{data: [{id, url, events, inbox_ids, created_at, disabled_at}]}`, never the secrets. `inbox_ids` is `null` for an endpoint of the whole account. |
| `POST /v1/webhooks` | `admin` | `201` `{id, secret}`. `400` for an event webhooks do not carry, or an inbox not of this account. |
| `DELETE /v1/webhooks/{id}` | `admin` | `204`. |

An endpoint in the default pod, made with a key of the whole account, hears about the whole account; one in another pod (`pod_id`) hears only that pod’s events. A key of one pod lists, adds and removes its own pod’s endpoints only, and what it adds hears that pod only, even in the default pod. Give `inbox_ids` and it hears only those inboxes’ events, and none that are not about an inbox (a domain, a key, a pod). An inbox it lists that is removed stops being heard; one whose every inbox is removed hears nothing. A key of one pod lists only its own pod’s inboxes in `inbox_ids`, and naming another pod is `403`.

## What arrives

Request:

```http
POST /hooks/pidgeon HTTP/1.1
Content-Type: application/json
Pidgeon-Event: message.received
Pidgeon-Signature: t=1794683000,v1=5f0c3e…

{
  "id": "4b3a2918-0716-4e5d-8c4b-3a2918071605",
  "type": "message.received",
  "created": "2026-11-14T12:03:20.000Z",
  "data": {
    "inbox_id": "5a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d",
    "message_id": "c3b2a1f0-9e8d-4c7b-a6f5-e4d3c2b1a0f9",
    "thread_id": "8f7e6d5c-4b3a-4291-8f0e-1d2c3b4a5968",
    "from": "ana@supplier.example",
    "subject": "Re: Your order",
    "spam": false
  }
}
```

- `id` is the event’s id, the same as in `GET /v1/events`: use it to ignore a delivery you already handled.
- Answer any `2xx` within 10 seconds. Anything else is retried, up to 5 more times.

## Check the signature

`Pidgeon-Signature` is `t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>" with your secret>`. Check it on the raw body, before parsing JSON. The SDKs refuse signatures older than 300 seconds, so a captured delivery cannot be replayed.

TypeScript:

```ts
import { verifyWebhook, PidgeonError } from '@zurchin/sdk';

export async function POST(request: Request) {
  const raw = await request.text();
  try {
    const event = await verifyWebhook(
      process.env.PIDGEON_WEBHOOK_SECRET!,
      raw,
      request.headers.get('pidgeon-signature'),
    );
    // event.id, event.type, event.created, event.data
    return new Response(null, { status: 204 });
  } catch (error) {
    if (error instanceof PidgeonError) return new Response(error.message, { status: 400 });
    throw error;
  }
}
```

Python:

```python
import os
from zurchin import verify_webhook, PidgeonError

def zurchin_webhook(raw_body: bytes, signature: str | None):
    try:
        event = verify_webhook(os.environ["PIDGEON_WEBHOOK_SECRET"], raw_body, signature)
    except PidgeonError as error:
        return 400, error.message
    # event["id"], event["type"], event["created"], event["data"]
    return 204, ""
```

Any language:

```text
expected = hex(HMAC_SHA256(secret, t + "." + raw_body))
accept if constant_time_equal(expected, v1) and |now - t| <= 300
```

## The event log

`GET /v1/events` lists the account’s events, newest first, kept for 90 days. Needs `read` access; a key of one pod sees its pod’s events.

curl:

```bash
curl "https://zurchin.com/v1/events?limit=50&type=message.sent" \
  -H "Authorization: Bearer $ZURCHIN_API_KEY"
```

Response:

```json
{
  "data": [
    {
      "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
      "type": "message.sent",
      "created_at": "2026-11-14T12:10:00.000Z",
      "pod_id": "7c6b5a49-3827-4161-9f0e-d1c2b3a49586",
      "data": { "message_id": "…", "inbox_id": "…", "thread_id": "…", "recipients": 1 }
    }
  ],
  "has_more": true,
  "next_cursor": "1842"
}
```

| Parameter | Value |
| --- | --- |
| `limit` | 1–100, default 50. |
| `cursor` | The last page’s `next_cursor`. |
| `type` | One event type. |

Types in the log: `api_key.created`, `api_key.delivered`, `api_key.revoked`, `app.connected`, `app.disconnected`, `member.invited`, `member.invitation_withdrawn`, `member.joined`, `member.removed`, `member.role_changed`, `pod.created`, `pod.renamed`, `pod.item_moved`, `pod.removed`, `inbox.created`, `inbox.removed`, `message.received`, `message.sent`, `message.failed`, `message.held`, `message.scheduled`, `message.delivered`, `message.delayed`, `message.bounced`, `message.complained`, `message.rejected`, `message.blocked`, `message.quarantined`, `message.released`, `message.exfiltration_blocked`, `inbox.updated`, `thread.updated`, `thread.deleted`, `draft.created`, `draft.approval_requested`, `draft.approved`, `draft.rejected`, `email.rule_added`, `email.rule_removed`, `email.suppressed`, `email.unsuppressed`, `email.domain_added`, `email.domain_verified`, `email.domain_broken`, `email.domain_removed`, `storage.warned`, `thread.notified`, `app_password.created`, `app_password.revoked`, `contact.updated`, `contact.deleted`, `calendar.event.created`, `calendar.event.updated`, `calendar.event.deleted`.
