Receive events
Register a URL with registerWebhookEndpoint, and the install POSTs a signed JSON event to it for each change of a type it chose. If your server is down, each event is retried for about 5 h 41 min, then kept 30 days for replay.
What arrives
Each active endpoint gets the events published after it was registered, of the types in its events. Left out or null, events is every type, one a later release adds included; answer 2xx to an event type you do not handle. A list stays as you set it: a type added later reaches only endpoints that take every type. Change the list with updateWebhookEndpoint, or by registering the URL again; an empty one is refused, so disable the endpoint instead. Every type includes transaction.detected, sent for a payment of any amount, dust included; leave it out of events to receive none. Up to 50 endpoints can be active at once.
sendWebhookTestEvent sends one endpoint.test event to an endpoint, whatever its events, so you can check your signature code and your answer before a payment arrives.
The URL may be https or plain http. Over http each event crosses the network in clear text: anyone on the path reads your customers' payments, though the signature still shows whether a body was changed. The URL must resolve to a public address, unless the install's operator allows the private one it names; each delivery checks the address it connects to.
| Field | Meaning |
|---|---|
id | The event's ID. Deduplicate on it. |
type | The event type, such as payout.confirmed |
aggregate_type | deposit_wallet, chain_transaction, withdrawal, or webhook_endpoint for endpoint.test |
aggregate_id | The ID of that customer address, payment, payout or webhook endpoint |
schema_version | The version of data |
occurred_at | When the change happened, not when it was sent. Order events by it. |
data | The event's own fields: see wallet, payment, payout and test events |
| Header | Value |
|---|---|
webhook-id | Same as id, as Standard Webhooks names it |
webhook-timestamp | Unix time of this attempt, in seconds |
webhook-signature | The signature to verify before you trust the body |
X-Fiatless-Event-Type | Same as type |
X-Fiatless-Delivery-Id | This delivery; a replay gets a new one |
X-Fiatless-Attempt | The attempt number within this delivery |
Content-Type | application/json |
User-Agent | fiatless-webhooks/1 |
Answer
Store the event, then answer 2xx within 10 s. Do slow work after you answer.
| Your answer | Result |
|---|---|
2xx in time | Delivered |
410 | This delivery stops at once and is dead-lettered. Later events still arrive. |
| Anything else, a redirect or headers over 64 KiB included, or no answer in time | Retried |
Delivery is at least once, and order is not guaranteed. Up to 4 requests reach one endpoint at once from each server of the install, so two events of one payment can be in your handler together. Deduplicate on id, and read the customer address, payment or payout for its current state. A transaction.detected not yet sent to an endpoint when a later transaction.confirmed or transaction.reverted of its payment exists for that endpoint is never sent there, and its delivery ends superseded; an endpoint that does not take the outcome gets the detection.
After the install's operator restores its database to an earlier point, the events since that point come again. Those not yet delivered then come under their old id. A payout's whole lifecycle, payout.queued to payout.confirmed, comes under new ids for the same payout id, so act once per payout and status, not once per event id. A payment made after that point comes again under a new transaction_id, with the same tx_hash: before you credit it, look its tx_hash up on its network, and move a credit you set under the old transaction_id to the new one rather than add a second. The operator tells you when such a restore happened.
Size
A payment's transaction.detected, transaction.confirmed and transaction.reverted list in data.wallets every customer the payment paid, so they grow with it. Each customer paid in one asset adds about 200 bytes with a 36-character external_id, and up to about 1.7 KB with an external_id of 255 characters, since <, > and & arrive escaped in six bytes each; each further asset adds its amount. A payment to 16,000 customers is about 3 MB.
Only the chain limits how many customers one payment pays: thousands for a token multi-send, about 32,000 for a Bitcoin transaction as large as a block. Accept request bodies as large as your largest payment's event. A smaller limit, such as nginx's default 1 MB, refuses every attempt at a payment to about 5,000 customers, and the event is dead-lettered.
Order events
Order the events of one customer address, payment or payout by occurred_at, never by arrival. A payment's events go by canonicality_generation first: Payments has the whole rule. A payout's go by occurred_at alone: see Payouts.
- Parse
occurred_atand compare times, not text. It is UTC to the microsecond with trailing zeros dropped, so10:00:01.8093Zis earlier than10:00:01.809308Zthough its text sorts after. - Milliseconds are enough. The install writes each event at least a millisecond after every event of the same customer address, payment or payout it had already saved, moving the event's time forward when it has to. So changes made together, such as
payout.confirmingandpayout.confirmed, read in the order they were made. - Changes saved at the same moment by separate processes, such as two history reads of one customer address finishing together, can be closer than a millisecond or share a time. When two events tie at your precision, read the customer address, payment or payout for its current state.
Retries
The first retry comes 10 s after a failed attempt, and each wait doubles. After 12 attempts the delivery is dead-lettered; the last attempt comes about 5 h 41 min after the first.
listWebhookDeliveries with status=failed lists dead letters, and with event_id one event's deliveries. getWebhookDelivery shows one delivery with the body each attempt sends. replayWebhookDelivery sends a failed one again, with the same event id and a new X-Fiatless-Delivery-Id. A delivery is removed 30 days after it ends, so replay a dead letter before then; one whose replay is still kept stays as long as that replay.