# Webhooks

Instead of asking the API what changed, let Lupeno tell you. A webhook endpoint is a URL of yours that Lupeno `POST`s an event to the moment something happens — an order paid, a ticket handed on, a guest checked in.

## Add an endpoint

In Lupeno, open **Organization → Integrations → Webhooks**, enter your URL and choose the events it should hear. Its **signing secret** (`whsec_…`) is shown once: store it beside your API key.

- The URL must be `https` (a test-mode endpoint may use plain `http`, say for a tunnel to your laptop) and must reach the public internet: addresses in private networks, loopback and link-local ranges are refused when you register them and again at every delivery.
- Lupeno follows **no redirects**: a `3xx` answer is a failed delivery. Register the final URL.
- A test-mode endpoint hears test events only, a live one live events only.

## Subscribe through the API

A tool that switches workflows on and off — n8n, Make, Zapier, or your own — can subscribe a URL with an API key instead of a person adding it on the screen (1.8.0).

```sh
curl https://api.lupeno.com/v1/webhook-subscriptions \
  -H "Authorization: Bearer $LUPENO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/lupeno-hook", "eventTypes": ["order.paid"], "description": "Orders to our CRM" }'
```

```json
{
  "subscription": {
    "id": "5e1c…",
    "url": "https://example.com/lupeno-hook",
    "eventTypes": ["order.paid"],
    "mode": "live",
    "eventId": null,
    "pii": false,
    "secretPrefix": "whsec_Ab3x",
    "state": "active",
    "createdAt": "2026-11-28T10:00:00.000Z"
  },
  "secret": "whsec_Ab3x…"
}
```

- **The secret is in this answer only.** Deliveries are signed with it exactly as below.
- **A subscription is its key's.** It hears the key's mode — a `lup_test_…` key's subscription hears test events only — and, for a key scoped to one event, only that event's orders, tickets, check-ins and refunds (`eventId`). It lives while the key does: **revoking the key removes its subscriptions**, and a key with an end takes them with it when it ends.
- **Any scope may subscribe.** Contacts unmasked and the checkout form's answers need the key's `pii` — `pii` follows the key unless you send `"pii": false`.
- **Subscribing a URL the key already subscribed replaces that subscription** — a new secret, and what waited for the old one is cancelled — so retrying a subscribe is safe without an `Idempotency-Key`, and a tool that switches a workflow on again after a missed unsubscribe never ends up with two.
- **`https://` on the public internet only** (`422 webhook.url_*`), even for a test key. At most **20 per key** and **50 per organization** (`409 webhook.too_many_subscriptions`); the Webhooks screen's own ten are separate.
- **`GET /v1/webhook-subscriptions`** lists the key's own subscriptions; **`DELETE /v1/webhook-subscriptions/{id}`** unsubscribes and cancels what still waited.
- The organization sees every subscription on its **Webhooks** screen under the key's name — with its log, **Send a test event**, pause and remove. A subscription paused there, or after fifty failures, is resumed there.

**Sample data.** `GET /v1/webhook-samples?type=order.paid&limit=3` answers envelopes as a subscription to that type would receive them: the newest resources of that kind the key reaches, masked as the key's `pii` says, or one made-up sample when there is none yet. Each says `"sample": true`, and nothing is sent anywhere — it is what a tool shows while you map fields.

## The events

| Type | When |
|---|---|
| `order.created` | An order is placed — by a buyer, in the portal or through the API — in whatever state it starts: waiting for its payment or for approval, or paid at once (then `order.paid` comes too). Within a minute (1.12.0) |
| `order.paid` | An order is paid — by card, transfer or at the desk; `data` is the order |
| `order.expired` | An unpaid order's hold ran out and its tickets went back on sale |
| `order.cancelled` | An order was cancelled |
| `refund.completed` | A refund reached the buyer; `data` is the refund: its `ticketIds`, the `donationMinor` and `extras` inside `amountMinor`, and the fee kept (`keptMinor`, 1.12.0) |
| `ticket.assigned` | A ticket was given a holder's name |
| `ticket.transferred` | A ticket was handed on: same ticket id, a new code — the old QR no longer admits |
| `ticket.voided` | A ticket no longer admits, for good: voided by the organizer, returned by a refund that succeeded, voided with its cancelled event, or replaced by an upgrade (refunds and cancellations since 1.12.0) |
| `checkin.recorded` | A ticket was admitted at the door |
| `checkin.reverted` | An admission was undone |
| `event.cancelled` | The organizer called the event off — a test-mode event's cancellation reaches test endpoints |
| `event.postponed` | The event moved to a new date; `data` is the event with its new `startsAt` and `endsAt`, and `postponedFrom` |
| `document.issued` | A document got its number: a proforma, a tax document, a credit note — Lupeno's own or your invoicing tool's. Once per document, within a minute; `data` is the document (1.12.0) |
| `order.forgotten` | The order's buyer and holders were forgotten (retention, their own request, the organizer's, or a closure); `data` is the order with placeholders and `forgottenAt` set — **drop any copy of those people you keep** |

There is no separate "ticket issued" event: `order.paid` is when an order's tickets are issued.

**A refund on its way.** A ticket reads `voided` from the moment its refund is asked for — it admits nobody —, but `ticket.voided` comes only once the refund succeeded: one that fails gives the ticket back, and nothing was announced.

**A bundle order is every included event's** (1.12.0): an endpoint or a subscription of an included event hears its `order.*` and the refunds that return its tickets, with that event's `items` and `ticketIds` only; the amounts are the whole order's. Its `document.issued` is the home event's.

**What webhooks do not tell.** A request's approval or decline, an unpaid order going overdue, a change of the buyer's details, and orders imported from another system. `order.created` says an order waits; read it again (`GET /v1/orders/{orderId}`) while it does, or list the states you act on — `GET /v1/events/{eventId}/orders?state=pending_approval` (or `approved`, `declined`, `pending_payment`, `overdue`).

## Try it

Each endpoint on the Webhooks screen has **Send a test event**: choose one of the types it hears and Lupeno sends a signed sample to your URL at once — through the same delivery path, signature and log as a real event, so the log shows your server's answer. A sample's envelope says `"sample": true`, its `data` is made up (ids that exist nowhere, people at `example.com`, masked unless the endpoint has the `pii` option), and nothing happened. It is sent once: a failed sample is never retried and never counts toward the endpoint's pause — so you can try a receiver on a paused endpoint before resuming it. Ten samples per ten minutes.

## A delivery

```http
POST /lupeno-hook HTTP/1.1
Content-Type: application/json
User-Agent: Lupeno-Webhooks/1.0 (+https://lupeno.com/developers)
Lupeno-Webhook-Id: 8b0f2c4e-3a5d-4c1e-9f7a-2d6b8e1c0a93
Lupeno-Signature: t=1792836000,v1=5f0c…e2a1

{
  "id": "8b0f2c4e-3a5d-4c1e-9f7a-2d6b8e1c0a93",
  "type": "order.paid",
  "occurredAt": "2026-10-24T10:00:00.000Z",
  "mode": "live",
  "apiVersion": "v1",
  "sample": false,
  "data": { "id": "…", "number": "2026000123", "state": "paid", "…": "…" }
}
```

`data` is the resource in the same shape as the [reference](https://lupeno.com/developers/reference) gives it: the `Order` for `order.*`, the `Ticket` for `ticket.*` and `checkin.*`, the `Refund` for `refund.completed`, the `Event` for `event.cancelled` and `event.postponed`, the `Document` for `document.issued`. Buyers' and holders' e-mails are masked unless the endpoint was registered with the `pii` option, which also adds the checkout form's `answers` to orders and tickets — a marketing consent with its `consentWordingId`, for a mailing tool to add only those who agreed. `apiVersion` names the version whose shapes `data` follows — `v1`; a delivery first sent before 24 November 2026 has none, read it as `v1`. `sample` is `true` only on a [test event](#try-it).

**`data` is the resource as it was when the delivery was first sent, not when the event happened.** Usually that is within a second; but after a pause — fifty failures, or by hand — everything that waited is rendered when it goes out, so an `order.paid` can arrive with the order already `refunded`, and a `checkin.recorded` with `checkedInAt: null` if the admission was undone meanwhile. Act on the resource's state (`data.state`, `data.checkedInAt`), never on the type alone. The body is then fixed at the first attempt; a retry or a replay sends the same bytes with a fresh signature.

## Verify the signature

`Lupeno-Signature` is `t=<unix seconds>,v1=<hex HMAC-SHA256>`, the HMAC over `` `${t}.${body}` `` with your signing secret. Verify it against the **raw** body — before any JSON parsing, which would change the bytes — and refuse a `t` more than five minutes from your clock, so a captured delivery cannot be replayed later.

```ts
import { createHmac, timingSafeEqual } from 'node:crypto';

export const verifyLupeno = (rawBody: string, header: string, secret: string): boolean => {
  const parts = Object.fromEntries(header.split(',').map((part) => part.trim().split('=')));
  const t = Number(parts.t);

  if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > 300) return false;

  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  const given = Buffer.from(parts.v1 ?? '', 'hex');

  return expected.length === given.length && timingSafeEqual(expected, given);
};
```

Or with the SDK, which does the same with WebCrypto (Node, Deno, Bun, Workers):

```ts
import { constructWebhookEvent } from '@lupeno/sdk';

const event = await constructWebhookEvent({
  payload: await request.text(),
  signature: request.headers.get('Lupeno-Signature'),
  secret: process.env.LUPENO_WEBHOOK_SECRET!,
});
```

## Answer quickly, process later

Answer `2xx` within **10 seconds**; do the work afterwards, from a queue of your own. Anything else — a timeout, a `3xx`, `4xx` or `5xx`, a refused connection — is a failed attempt, retried after **1 min, 5 min, 30 min, 2 h and 12 h**. After **50 failures in a row** the endpoint is paused and its owners are told by mail; resume it from the Webhooks screen once it is fixed.

**Deliveries can repeat and arrive out of order.** Deduplicate on the event's `id` (also in `Lupeno-Webhook-Id`), and when order matters, compare `occurredAt` or read the resource's current state from the API.

## Replay

Every delivery and its attempts are in the endpoint's log on the Webhooks screen for 30 days, with the status your server answered. **Replay** sends a delivery again — useful after an outage on your side.
