1. Register the receiver
Point the subscription at a publicly reachable HTTPS handler with valid TLS. Use the final URL that accepts JSONPOST requests. The delivery service sends directly to that address.
In order-webhook.json, replace the example URL with your receiver. Run the signed HTTP request with a key that has public-api:webhooks:write. Use events: ["*"] if your handler needs all event types. For payload_version use v2 when supplying the field.
order-webhook.json
201, save result.endpoint.id and put result.endpoint.secret in your secret store. The subscription secret verifies webhook deliveries. Your API key and API HMAC secret authorize requests to the exchange. Subscription list and detail responses expose the secret_fingerprint for identification.
2. Send a test
Put the subscription ID returned by the API intest-webhook.json.
test-webhook.json
201 registers the test. The payload has type: "api.test", test: true, and sample_of: "order.status_changed" when you choose this sample. When endpoint_id is omitted, the API sends to active subscriptions for event_type or defaults to api.test. A subscription for * also matches. Confirm receipt in delivery history.
3. Verify the signature
Read the exact body bytes before parsing JSON. RequireX-Webhook-Signature-Version: v2. The HMAC input consists of seven lines joined by LF, with no trailing newline.
Compute HMAC-SHA256 with the subscription secret. The
X-Webhook-Signature header contains sha256= followed by the lowercase hexadecimal value. Compare in constant time and match the signed event ID and type against the JSON. Use the timestamp to reject stale attempts. The example allows 300 seconds of clock skew.
Save the verification function as verify-webhook.mjs. It accepts the original bytes, request headers and subscription secret. Omit the optional clock argument when verifying live deliveries.
verify-webhook.mjs
test-webhook.mjs and run node test-webhook.mjs. It prints the event ID for the original bytes and null after a newline is added.
test-webhook.mjs
4. Acknowledge and process
- Reject a failed verification without changing the resource.
- Insert the verified event into durable storage. Give the event ID a uniqueness constraint scoped to its source and receiver. Return
2xxafter a successful durable write or completed processing. If the same verified event is already stored, return2xxand skip the duplicate write. - Route
api.testseparately from production actions. For actual events, usedata.resource.idwith the read operation for that resource, such asGET /api/v3/private/exchange/orders/{order}. The resource fieldstypeandidcan benull. A concurrent or retried notification can arrive after a newer event, so fetch the resource when you need its latest state.
id, type, created_at, request_id, correlation_id, payload_version: "v2", and data.resource. X-Request-Id and X-Correlation-Id help trace the source request. Delivery retries retain the event ID and change the attempt number and signature.
Receive and store the event in PHP
The HTTP timeout defaults to 8 seconds. The operator can set 1–60 seconds. Use a durable inbox if processing may take longer. Create this PostgreSQL table once.WEBHOOK_SECRET to the subscription secret, WEBHOOK_RECEIVER_ID to a stable local identifier for this exchange and receiver, and WEBHOOK_PG_DSN to a PostgreSQL PDO connection string. Supply database credentials through your service environment. This receiver accepts up to 1 MiB of raw input and returns 413 above its local limit.
receiver.php
processed_at in one transaction. For an external write, use a separate durable operation key. Repeated notifications for a payment must never authorize another credit.
Receive and store the event in Node.js
Use the same inbox table. Place the receiver besideverify-webhook.mjs. Install the PostgreSQL client with npm install pg. Set WEBHOOK_SECRET, WEBHOOK_RECEIVER_ID, and the PostgreSQL client environment variables for your database. Start the handler with node receiver.mjs behind your HTTPS reverse proxy. This example sets a local body size limit of 1 MiB.
receiver.mjs
Event types
Read the installation’s catalog inresult.events from GET /api/v3/private/webhooks.
Change or revoke a subscription
Usepublic-api:webhooks:read for GET and public-api:webhooks:write for changes.
Use an idempotency key for creation or rotation. Within the response retention window, a replay can recover that operation’s secret. If the response can no longer be replayed, check for the existing subscription and rotate its secret if you need to recover access to delivery verification.
Prompt for building a receiver
Prompt for building a receiver