# Webhook events

Source: https://docs.formance.com/reference/api/webhook-events

Stack: v3.2

The stack emits an event for every state change worth reacting to. Subscribe by event
type, verify the signature, and treat delivery as at-least-once.

## Delivery contract

Deliveries are at-least-once and unordered. Every payload carries a unique `id` —
deduplicate on it and make your handler idempotent. Respond `2xx` within 30 seconds; the
sender's HTTP client times out at that point and counts the attempt as retryable.

Not every failure is retried. `408`, `429`, `5xx` and transport errors (DNS, TLS, connection,
timeout) are retryable; **every other `4xx` is terminal** and is never attempted again. Do not
return a permanent `400` expecting redelivery.

Retryable attempts back off exponentially without jitter — 1 minute, doubling to a 1 hour
ceiling — and are bounded by both a 15-attempt cap and a 10-hour retry window, whichever hits
first. `Retry-After` is honored when it asks for a longer wait than the computed backoff,
clamped to 6 hours. After the budget is exhausted the delivery is terminal. These are global
service defaults, not per-configuration API options.

The 30/90-day figures are _retention_, not retry: succeeded deliveries are kept 30 days and
failed or cancelled ones 90 days, which is how long inspection and replay stay possible.

See [Receiving webhooks](https://docs.formance.com/v3.2/modules/webhooks/receiving) for the full receiver contract.

| Field     | Type               | Notes                                                                 |
| --------- | ------------------ | --------------------------------------------------------------------- |
| `id`      | string (uuid)      | Unique per delivery attempt group. Deduplicate on this.               |
| `type`    | string             | Dotted event type, e.g. `ledger.committed_transactions`.              |
| `date`    | string (date-time) | When the event was emitted, not when it was delivered.                |
| `payload` | object             | The resource that changed, in the same shape the REST API returns it. |

```json
{
  "id": "e5f2…8c1a",
  "type": "ledger.committed_transactions",
  "date": "2026-07-24T09:12:03.612Z",
  "payload": {
    "ledger": "ledger001",
    "transactions": [{ "id": 1234 }]
  }
}
```

## Verifying a delivery

Each request carries `formance-webhook-signature` computed over
`{webhookId}.{timestamp}.{rawBody}`. The id and timestamp come from the
`formance-webhook-id` and `formance-webhook-timestamp` headers sent with every delivery.
Compute HMAC-SHA256, base64-encode the digest, and compare in constant time. The header holds
a space-separated list of `<version>,<signature>` pairs — today the sender emits exactly one
`v1` pair, so split on whitespace, skip any version you do not know, and accept a match on any
remaining `v1` entry rather than assuming a single value.

A valid signature never expires on its own: the sender signs the timestamp but enforces no
tolerance on it, so an attacker who captures one valid request can replay it indefinitely
unless the receiver rejects stale timestamps itself. Parse `formance-webhook-timestamp` (Unix
seconds, re-generated on every attempt) and reject anything outside your own window before
doing any work. Five minutes is the usual choice, and it requires a synchronized server clock —
the check is bidirectional, so a fast local clock rejects legitimate deliveries.

```typescript
import { createHmac, timingSafeEqual } from "node:crypto"

const TOLERANCE_SECONDS = 5 * 60

// Node/Express type these as string | string[] | undefined: a duplicated header
// arrives as an array, so narrow to a single string rather than only truthiness
const header = (value: string | string[] | undefined) =>
  typeof value === "string" ? value : undefined

const id        = header(req.headers["formance-webhook-id"])
const timestamp = header(req.headers["formance-webhook-timestamp"])
const sigHeader = header(req.headers["formance-webhook-signature"])

if (!id || !timestamp || !sigHeader) {
  // missing, duplicated, or non-string headers — reject without processing
  return res.status(400).end()
}

// reject replays before spending any work on the signature
const attemptedAt = Number(timestamp)
if (!Number.isFinite(attemptedAt)) {
  return res.status(400).end()
}
const ageSeconds = Math.floor(Date.now() / 1000) - attemptedAt
if (Math.abs(ageSeconds) > TOLERANCE_SECONDS) {
  return res.status(400).end()
}

const expectedBuf = Buffer.from(
  createHmac("sha256", process.env.WEBHOOK_SECRET)
    .update(`${id}.${timestamp}.`)
    .update(rawBody)        // raw bytes — do not re-serialize the parsed JSON
    .digest("base64")
)

// the header is a space-separated list of `<version>,<signature>` pairs; today the
// sender emits exactly one v1 pair, so match the reference verifier and accept any
const ok = sigHeader.split(" ").some((versioned) => {
  const [version, signature] = versioned.split(",")
  if (version !== "v1" || !signature) return false

  const receivedBuf = Buffer.from(signature)
  // timingSafeEqual throws if lengths differ — guard first
  return expectedBuf.length === receivedBuf.length &&
    timingSafeEqual(expectedBuf, receivedBuf)
})

if (!ok) {
  // unverified — do not read, parse, or act on the body
  return res.status(401).end()
}

// only now is the payload trustworthy
const event = JSON.parse(rawBody.toString("utf8"))
```

Rotating a secret replaces it outright — there is no overlapping window in which the sender
signs with both the old and the new one, so do not expect rotation to produce two signatures
in the header. The dispatcher reads the current configuration before each attempt, so a queued
retry is signed with the new secret while a request already in flight can still carry the old
one. To rotate without dropping deliveries, have the receiver accept both secrets, rotate the
configuration, then retire the old secret once in-flight attempts have drained.

## Event catalog

| Type                                                | Module   | Emitted when                                                                                                                 |
| --------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `ledger.committed_transactions`                     | Ledger   | One or more transactions were committed. Payload carries the full transactions, so most integrations need no follow-up read. |
| `ledger.reverted_transaction`                       | Ledger   | A transaction was reverted. Payload carries both the original and the compensating transaction.                              |
| `ledger.saved_metadata`                             | Ledger   | Metadata was written to a transaction or account.                                                                            |
| `ledger.deleted_metadata`                           | Ledger   | A metadata key was removed.                                                                                                  |
| `payments.saved_payment`                            | Payments | A payment was ingested or updated by a connector.                                                                            |
| `payments.saved_payment_initiation`                 | Payments | An outbound payment initiation was created or changed status.                                                                |
| `payments.saved_payment_initiation_adjustment`      | Payments | A payment initiation status adjustment was recorded. Payload carries the new status and any error.                           |
| `payments.saved_payment_initiation_related_payment` | Payments | A payment was linked to a payment initiation.                                                                                |
| `payments.saved_account`                            | Payments | A connector account was created or updated.                                                                                  |
| `payments.saved_balance`                            | Payments | A connector account balance was updated.                                                                                     |
| `payments.saved_bank_account`                       | Payments | A bank account was created or updated.                                                                                       |
| `payments.saved_pool`                               | Payments | A payment pool was created or updated.                                                                                       |
| `payments.deleted_pool`                             | Payments | A payment pool was deleted.                                                                                                  |
| `payments.connector_reset`                          | Payments | A connector was reset and will re-ingest from scratch.                                                                       |
| `orchestration.started_workflow`                    | Flows    | A workflow instance began execution.                                                                                         |
| `orchestration.succeeded_workflow`                  | Flows    | A workflow instance completed successfully.                                                                                  |
| `orchestration.failed_workflow`                     | Flows    | A workflow instance failed. Payload carries the instance ID and error.                                                       |
| `orchestration.started_workflow_stage`              | Flows    | A workflow stage began execution. Payload carries the instance ID and stage number.                                          |
| `orchestration.succeeded_workflow_stage`            | Flows    | A workflow stage completed successfully.                                                                                     |
| `orchestration.failed_workflow_stage`               | Flows    | A workflow stage failed. Payload carries the instance ID, stage number, and error.                                           |
| `orchestration.succeeded_trigger`                   | Flows    | A trigger evaluation succeeded and launched a workflow instance.                                                             |
| `orchestration.failed_trigger`                      | Flows    | A trigger evaluation failed. Payload names the trigger ID and the error.                                                     |
