Skip to main content
When the status of an order changes, Exchanger API sends your HTTPS handler a compact notification. Use its resource ID to read the current state. If the same event arrives again, acknowledge it and apply your business change once.

1. Register the receiver

Point the subscription at a publicly reachable HTTPS handler with valid TLS. Use the final URL that accepts JSON POST 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
From 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 in test-webhook.json.
test-webhook.json
A 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. Require X-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
Save the following fixture alongside the module as 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

  1. Reject a failed verification without changing the resource.
  2. Insert the verified event into durable storage. Give the event ID a uniqueness constraint scoped to its source and receiver. Return 2xx after a successful durable write or completed processing. If the same verified event is already stored, return 2xx and skip the duplicate write.
  3. Route api.test separately from production actions. For actual events, use data.resource.id with the read operation for that resource, such as GET /api/v3/private/exchange/orders/{order}. The resource fields type and id can be null. A concurrent or retried notification can arrive after a newer event, so fetch the resource when you need its latest state.
A v2 notification includes 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.
Run this endpoint with PHP and PDO_PGSQL. Set 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
A worker reads pending rows, fetches the resource, and marks the row processed. Commit any local business update and 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 beside verify-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 in result.events from GET /api/v3/private/webhooks.

Change or revoke a subscription

Use public-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.