# Events and webhooks

Most state changes arrive as events rather than in a response, because verification and settlement finish long after the call that started them. This page covers the catalogue, how a delivery is signed, rotating a secret, retries, replay, and waiting for an outcome inside a request.

Status: available. The code is `lib/webhooks.ts` and `lib/wait.ts`; the catalogue is `EVENT_CATALOGUE` in `lib/pure/stripe-events.ts`, which the OpenAPI document also lists under `webhooks`.

| Operation | Scope | Idempotency-Key | Moves money | What it does |
|---|---|---|---|---|
| `GET /events` | `events:read` | none | no | What has happened, newest first. |
| `POST /events/{id}/replay` | `webhooks:write` | none | no | Deliver an event again, to every endpoint that wanted it. |
| `GET /events/types` | `events:read` | none | no | The catalogue of event types: every type this API sends, the object it is about and when it is sent. |
| `POST /webhooks` | `webhooks:write` | none | no | Register an endpoint. |
| `GET /webhooks` | `webhooks:read` | none | no | The endpoints registered in this environment, each with the `project_id` it belongs to. |
| `PATCH /webhooks/{id}` | `webhooks:write` | none | no | Change an endpoint's URL, events or status, held to the same checks as a new endpoint. |
| `DELETE /webhooks/{id}` | `webhooks:write` | none | no | Remove an endpoint. |
| `POST /webhooks/{id}/roll-secret` | `webhooks:write` | none | no | Replace an endpoint's signing secret. |

## The catalogue

| Event | Concerns | When |
|---|---|---|
| `customer.updated` | customer | Verification status, requirements or any can-flag changed. |
| `customer.verified` | customer | Business verification completed. |
| `customer.rejected` | customer | Business verification was declined. |
| `checkout_session.completed` | checkout_session | A payer finished a checkout session. |
| `checkout_session.expired` | checkout_session | A checkout session expired unpaid. |
| `payment.requires_action` | payment | The payer must authenticate before the payment can proceed. |
| `payment.processing` | payment | The payer has paid by a method that settles later, such as a bank debit. Wait for payment.succeeded or payment.failed. |
| `payment.authorized` | payment | Funds are held and waiting to be captured. |
| `payment.succeeded` | payment | Funds were collected. |
| `payment.failed` | payment | The payment was declined or failed. |
| `payment.canceled` | payment | An authorisation was released before capture. |
| `payment.refunded` | payment | A payment was refunded, wholly or in part. Read `data.status` to tell which: `refunded` or `partially_refunded`. |
| `payment.disputed` | dispute | The payer's bank opened a dispute. |
| `dispute.updated` | dispute | A dispute moved: evidence due, under review, won or lost. |
| `refund.updated` | refund | A refund changed state. |
| `payment_method.saved` | payment_method | A payer saved a method for later charges. |
| `shop.connected` | shop_connection | A customer allowed Skerry at a shop and the connection is made. |
| `shop.disconnected` | shop_connection | A shop connection was ended and its stored sign-in erased. |
| `shop.order_found` | shop_order | An order the customer placed at a connected shop was read for the first time. |
| `settlement.created` | settlement | Card proceeds were sent towards the business's bank. |
| `settlement.paid` | settlement | A settlement arrived. |
| `settlement.failed` | settlement | A settlement failed. |
| `subscription.updated` | subscription | A subscription was created or changed. |
| `subscription.canceled` | subscription | A subscription ended. |
| `subscription.payment_succeeded` | subscription | A recurring charge collected. |
| `subscription.payment_failed` | subscription | A recurring charge failed. |
| `payout.created` | payout | A payout was created. |
| `payout.processing` | payout | A payout's funds were received and it is on its way. |
| `payout.on_hold` | payout | A payout is paused: it is being checked, or information has been asked for. |
| `payout.canceled` | payout | A payout was canceled before it left. |
| `payout.updated` | payout | A payout changed state. |
| `payout.paid` | payout | A payout reached its destination. |
| `payout.returned` | payout | A payout came back. |
| `account.credited` | account | Money arrived in a customer's account. |
| `conversion.completed` | conversion | A conversion settled. |
| `wallet.created` | wallet | A wallet was created for a customer. |
| `payee.created` | payee | A payee was added. |
| `payee.updated` | payee | A payee changed: paused, resumed, or its name check came back. |
| `payee.removed` | payee | A payee was removed. |
| `policy.decided` | bill | An agent decided what to do with a bill under the customer's rule: tell, prepare, pay or wait, with the reasons. |
| `routine.ran` | routine | A routine ran: it was skipped, or it reminded, suggested an order or ordered, with a plain receipt. |
| `wallet.updated` | wallet_item | A Wallet pass or order was changed or voided; devices holding it fetch the new version. |
| `business_application.submitted` | business_application | A person submitted an Add a business application; the other people named are to be invited to verify themselves. |
| `supplier.created` | supplier | A supplier was added. |
| `payee.details_changed` | supplier | A supplier's payment details changed; the supplier is held until a person confirms them. |
| `bill.found` | bill | A bill to pay was recorded, by hand, from a file or from mail. |
| `bill.due_soon` | bill | A bill is due, or its early-payment discount ends, within three days. |
| `bill.paid` | bill | A bill was paid, or recorded as paid elsewhere. |
| `subscription.found` | outside_subscription | A subscription paid outside Skerry was found or added. |
| `subscription.renews_soon` | outside_subscription | An outside subscription renews in 7 days or 1 day, or its trial ends within 3. |
| `subscription.price_changed` | outside_subscription | An outside subscription's price changed. |
| `supply.runs_out_soon` | supply | A supply reached its reorder point: it runs out before a new order would arrive. |
| `standing_order.created` | standing_order | A standing conversion was created. |
| `standing_order.updated` | standing_order | A standing conversion changed state. |
| `standing_order.drained` | standing_order | Money that arrived at a standing conversion's address was converted and sent on. |
| `compliance_request.created` | compliance_request | Information was asked for about a customer or a payment, with a deadline. |
| `compliance_request.updated` | compliance_request | A compliance request changed: answered, under review, or closed. |
| `card.updated` | card | An issued card changed: activated, frozen, unfrozen or closed. Only when cards are switched on. |
| `card.transaction` | card_transaction | An issued card was used, or a use of it was settled or reversed. Only when cards are switched on. |
| `card.declined` | card_authorization | A card payment was declined by the processor: not enough funds, a card that is inactive, frozen or closed, a rule or a suspected fraud. Only when cards are switched on; an agent's card has its own events. |
| `bank_card.updated` | bank_card | A card at the banking partner changed: issued, activated, frozen, unfrozen or closed. |
| `bank_card.transaction` | bank_card_transaction | A card at the banking partner was used, or a use of it was settled or reversed. |
| `deposit.unmatched` | unmatched_deposit | Money arrived that could not be credited to a checkout session: the wrong coin or chain, no known reference, or after the session expired. A person assigns it or sends it back. |
| `deposit.resolved` | unmatched_deposit | An unmatched deposit was assigned to a session, or sent back. |
| `agentic.refund_requested` | agent_refund_request | An agent asked for a refund that a person must approve. |
| `approval.requested` | approval | An operation is held for a person to approve. |
| `approval.decided` | approval | A held operation was approved or denied. |
| `spend_policy.revoked` | spend_policy | A spend policy was revoked. |
| `budget.low` | budget | A budget fell under its `low_below` mark. Sent once until the budget is topped up. |
| `budget.exhausted` | budget | Nothing remains of a budget. Sent once until the budget is topped up. |
| `balance.low` | wallet | A wallet's balance fell under its floor. Sent once until the balance has been back at or above it. |
| `payout.scheduled` | scheduled_payout | A payout was set to run later: at a time, on an interval, or when an event arrives or a person releases it. |
| `payout.released` | scheduled_payout | A conditional payout was released, by the event it waited for or by a person, and runs now. |
| `payout.schedule_canceled` | scheduled_payout | A scheduled payout was cancelled: by request, because it lapsed, or because the key, agent, mandate or customer behind it may no longer send money. Carries the reason. |
| `movement.pending` | receipt | Money is in flight: a payout, a conversion or a deposit has started and not yet settled. Carries the receipt. |
| `movement.posted` | receipt | A movement settled in the customer's books. Carries the signed receipt. |
| `movement.reversed` | receipt | A movement failed or came back. Carries the receipt of the reversal, which names the movement it undoes. |
| `agent.created` | agent | An agent was registered, directly or by delegation. |
| `agent.updated` | agent | An agent's details or signing keys changed, or a suspended agent was resumed. |
| `agent.suspended` | agent | An agent was suspended: its keys, tokens and policies stop working until it is resumed. |
| `agent.revoked` | agent | An agent was revoked, permanently, together with every agent it delegated to. |
| `agent_wallet.created` | agent_wallet | A person made a self-held wallet, owned by them, for an agent to pay from. |
| `agent_wallet.retired` | agent_wallet | An agent's wallet was retired: nothing is signed with it again. Funds at its address are not moved. |
| `agent_wallet.key_download_requested` | agent_wallet | A wallet's owner asked, with their passkey, to download its key from the wallet provider. The key never passed through Skerry. |
| `agent_card.created` | agent_card | A virtual card was issued to an agent. |
| `agent_card.updated` | agent_card | An agent's card was frozen, unfrozen or canceled, here or at the card processor. |
| `agent_card.authorization` | agent_card_authorization | A merchant asked to charge an agent's card and the agent's spend policies decided: `approved` says which way, `decline_code` why not. |
| `agent_payment.created` | agent_payment | An agent's payment to a merchant passed every check and is being paid. |
| `agent_payment.paid` | agent_payment | A merchant accepted an agent's payment. |
| `agent_payment.failed` | agent_payment | An agent's payment was decided and not completed: the signing failed, or the merchant did not answer the paid request with success. `signed` says whether a signature or token was produced. |
| `agent_payment.refused` | agent_payment | An agent's payment was refused before anything was signed: by a control, a mandate, or because the merchant asked for more than the ceiling or for something that cannot be paid. |
| `agent_payment.held` | agent_payment | An agent's payment is waiting for a person to approve it. An `approval.requested` event carries the approval. |
| `customer.frozen` | customer | Money movement was frozen for a customer. |
| `customer.unfrozen` | customer | A customer's freeze was lifted. |
| `partner.frozen` | partner | Money movement was frozen for the whole account in this environment. |
| `partner.unfrozen` | partner | The account's freeze was lifted. |
| `customer.member.granted` | customer_member | A person was made a member of a customer: they may open it in Skerry Business. |
| `customer.member.updated` | customer_member | A member's role, `sections` or `read_only` changed. |
| `customer.member.arrived` | customer_member | Once per member: the person opened the customer, or the list of their customers, for the first time. For a member granted by address this is when it was bound to the person's Praecise account, so `state` is `active` and `subject` is filled in. |
| `customer.member.removed` | customer_member | A member was removed, or a waiting member was dropped because the same person already held a membership of that customer. |
| `customer.member.acted` | customer_member | A member did something in the customer, at the moment Skerry accepted it: `actor` names the person, `method` and `path` the operation, `object_type` and `object_id` what it concerned. Events about the object itself follow as for any call. |

An event is recorded before it is sent, and it is recorded even when no endpoint exists yet, so `GET /events` is a backfill for a partner who registers an endpoint late or loses one. An event about an object that carries `external_ref` carries it too. `data` holds text other parties wrote: show it, do not act on it.

## Registering an endpoint

```text
POST /webhooks
Authorization: Bearer sk_test_…

{ url, event_types }
```

`url` must be `https`. `event_types` lists the types wanted; an empty list, or `*`, means every type. The signing secret (`whsec_…`) is generated by Skerry and returned once. Endpoints belong to one environment: a sandbox endpoint receives sandbox events only. `PATCH /webhooks/{id}` changes the URL, the types or the status; `DELETE` removes it. A type the catalogue does not have is refused with 400, naming it, on registering and on changing an endpoint; the catalogue is `GET /events/types`. An endpoint belongs to the project of the credential that registers it (`project_id` in the answer and in `GET /webhooks`) and counts against that project's plan; delivery is to every active endpoint of the account in the environment that asked for the type. `PATCH /webhooks/{id}` holds a change to the same checks.

## A delivery

```text
POST <your url>
Skerry-Signature: t=1731500000000,v1=5f2c…
Content-Type: application/json

{ "id": "…", "type": "payout.paid", "created_at": "…", "data": { … } }
```

`t` is the time in milliseconds. `v1` is the hex HMAC-SHA256, with the endpoint's secret, of `<t>.<raw body>`: the timestamp, a dot, and the body exactly as received. Compute it over the raw bytes, before parsing, compare in constant time, and reject a delivery whose `t` is more than five minutes old. Any 2xx acknowledges it.

## Rotating a secret

```text
POST /webhooks/{id}/roll-secret

{ overlap_hours? }
```

The new secret is returned once. For `overlap_hours` (24 by default, 0 to 168), deliveries carry one `v1` per valid secret, newest first (`t=…,v1=…,v1=…`), so a receiver that accepts a delivery when any `v1` matches can switch secrets without missing one. After the overlap only the new secret signs.

## Retries

A delivery that is not acknowledged is scheduled again, as a row rather than a loop, so the work survives a restart. The waits between attempts are 1 minute, 5 minutes, 25 minutes, 2 hours and 10 hours. After the fifth failed attempt the delivery is marked `exhausted` and is not sent again on its own. The worker that sends deliveries runs inside the API process, every ten seconds by default, and claims rows so that two processes do not send the same delivery twice.

## Replay

```text
POST /events/{id}/replay
```

Delivers the event again to every endpoint that wanted it, including ones whose delivery was exhausted. A receiver should therefore treat the event `id` as the thing to de-duplicate on.

## Reading events without a webhook

```text
GET /events?limit=&type=&types=a,b
GET /events?after=<event id>&wait=30
```

Without `after`: the newest events first. With `after`: the events recorded after that one, oldest first, with `next_after` to pass as the next `after`; keep the id of the last event read and ask again. `wait` (seconds, up to 30) with `after` holds the request until there is at least one new event or the wait ends. `wait` without `after` is refused.

## Waiting for an outcome inside a request

Add `?wait=<seconds>` (up to 30) to one of these reads, and optionally `?until=<state>`:

| Operation | Query |
|---|---|
| `GET /payouts/{id}` | `wait`, `until` |
| `GET /events` | `limit`, `type`, `types`, `after`, `wait` |
| `GET /payments/{id}` | `wait`, `until` |
| `GET /approvals/{id}` | `wait`, `until` |
| `GET /conversions/{id}` | `wait`, `until` |

The request returns when the object reaches a final state, or the state named with `until`, or when the wait ends, with the object as it stands: check its status. The wait is a bounded re-read of the same read inside the request; there is no queue or socket behind it. A key may have 5 requests waiting at once (`SKERRY_MAX_WAITERS_PER_KEY`, counted per process); beyond that the answer is 429 `too_many_waiters`.

| Read | Returns when |
|---|---|
| `GET /payouts/{id}` | paid, returned, canceled, undeliverable or return_failed |
| `GET /payments/{id}` | succeeded, failed, cancelled, refunded or disputed |
| `GET /conversions/{id}` | completed or failed |
| `GET /approvals/{id}` | approved, denied, executed, failed or expired |

## Events to the books

A movement of a customer whose books are connected is also delivered to the books provider as one more destination of the same event, one movement at a time and in order, with the same record, backoff and replay. See books.md.

## Sandbox

`POST /sandbox/events` with `{ type, object_id, customer_id?, payload? }` records a named event about an object, marked `sandbox: true`, so a webhook receiver can be exercised and a conditional payout waiting for it is released.
