# Outbound webhooks

Audiobly can call your server when something happens: a transcript is ready, an event is approved, content is generated, an order is paid, a delegate checks in. Register an HTTPS endpoint, choose the event types it receives, and verify each delivery's signature.

All management endpoints need organisation-management permission (an admin user or an API key with that scope).

## 1. Register an endpoint

```bash
curl -sX POST "https://api.audiobly.com/v1/webhook-endpoints" \
  -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/hooks/audiobly",
       "subscribed_events": ["event.transcript_ready", "asset.created"],
       "enabled": true}'
```

The response (201) includes `secret`, starting `whsec_`. It is shown **only once**: store it to verify signatures. The URL must be `http` or `https` with a public host (use `https`); `localhost` and private, loopback or link-local IP addresses are refused, and delivery itself never connects to an internal address.

| Task | Call |
|---|---|
| List endpoints (newest first, paginated) | `GET /v1/webhook-endpoints?limit=&offset=` |
| Change URL, events or switch on/off (only the fields sent change; `?discard_held=true` with a switch-on drops the held events instead of sending them) | `PUT /v1/webhook-endpoints/{endpoint_id}` |
| Delete | `DELETE /v1/webhook-endpoints/{endpoint_id}` (204) |
| Delivery log (filter by `status`: `pending`, `failed` (retry scheduled), `succeeded`, `exhausted`, `held` (waiting for its switched-off endpoint); and `endpoint_id`) | `GET /v1/webhook-deliveries` |
| Send a past delivery again (starts a fresh cycle of six attempts) | `POST /v1/webhook-deliveries/{delivery_id}/redeliver` (202; 409 if the endpoint is disabled) |

## 2. Event catalogue

Every delivery is a JSON `POST` with this body:

```json
{"data":{"event_id":"…","status":"TRANSCRIPT_READY"},"event_type":"event.transcript_ready","occurred_at":"2026-05-14T15:02:11.204518+00:00"}
```

| `event_type` | When | `data` |
|---|---|---|
| `event.transcript_ready` | The event's transcript is ready for review (after personal-data detection, or when that step is skipped) | `event_id`, `status` |
| `event.approved` | The transcript was approved, by an editor or automatically | `event_id`, `status` |
| `event.generation_complete` | Content generation finished | `event_id`, `status` |
| `event.delivered` | Generation finished and the event's Publish automatically setting marked it delivered | `event_id`, `status` |
| `event.failed` | A pipeline step failed | `event_id`, `status`, `failure_stage`: `transcription`, `pii_detection` (personal-data detection) or `generation` |
| `asset.created` | A content asset was created (summary, blog post, quote cards, …) | `event_id`, `asset_id`, `asset_type`, and, for per-session content, `session_id` (possibly null) |
| `order.paid` | An order was created already paid through the orders API (`payment_status: "paid"`). Payments confirmed through self-service registration do not send it | `order_id`, `order_number`, `total`, `currency` |
| `ticket.transferred` | A ticket was assigned or transferred (by the delegate or the organiser) | `ticket_id`, `from_email` (null on first assignment), `to_email` |
| `attendee.checked_in` | A ticket was checked in at the door with Audiobly ticketing (not repeated for a second scan; Ticket Tailor door scans do not send it) | `ticket_id`, `attendee_id` (can be null), `checked_in_at` |
| `attendee.created` | Someone registered through self-service registration (`POST /v1/events/{event_id}/registrations`); imports, integrations, orders and manual adds do not send it | `attendee_id`, `email`, `name` |

Subscribing to a type not in this list is refused. Each type fires at most once per event (or order, ticket, asset) per endpoint: a later re-transcription, re-approval or repeated failure at the same stage is not sent again.

## 3. Verify the signature

Each delivery carries `X-Audiobly-Signature: t=<unix seconds>,v1=<hex>`. `v1` is the HMAC-SHA256, keyed with your whole endpoint secret (including `whsec_`), of `"<t>.<raw body>"`; `t` is the time of that attempt, not `occurred_at`. The body is sent as compact JSON with sorted keys; verify against the raw bytes you received, not a re-serialised copy.

```python
import hashlib, hmac, time

def verify(secret: str, header: str, body: bytes, tolerance: int = 300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t, sig = int(parts["t"]), parts["v1"]
    if abs(time.time() - t) > tolerance:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, sig)
```

Reject deliveries older than a few minutes to stop replays. There is no secret rotation: create a new endpoint, switch to it, then delete the old one. The live caption webhook (*Live translation* guide) is separate and signs differently (`sha256=<hex>`, no timestamp) under the same header name.

## 4. Retries and switching off

- Answer with any 2xx within 10 seconds, at the registered URL (do not redirect). Anything else, or no answer, counts as a failure. A delivery to an internal address is `exhausted` after one attempt.
- A failed delivery is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours (six attempts in all), then marked `exhausted`.
- After 20 deliveries in a row have used up all their attempts, the endpoint is switched off (`enabled: false`, `disabled_reason: auto_disabled_consecutive_failures`). Switching it back on with `PUT` clears the count.
- While an endpoint is switched off (by you or automatically), its events are kept as deliveries with status `held`: the newest 1,000 per endpoint, none older than 7 days (older ones are dropped). A delivery that was waiting or retrying when the endpoint was switched off becomes `held` too.
- Switching the endpoint back on with `PUT … {"enabled": true}` sends the held deliveries in the order the events happened, each with a fresh cycle of six attempts. They go one after another until one fails (it then retries on the schedule above) and the rest are sent as usual from then on, so keep processing idempotent and order-tolerant. Held events of types the endpoint no longer subscribes to are dropped. To switch it on without sending them, add `?discard_held=true`.

Process deliveries idempotently, keyed on `event_type` plus the ids in `data` (no delivery id is sent, and `occurred_at` is identical on every retry and redelivery): a manual redelivery sends the same body again.
