Webhooks
Webhooks let Paxon tell your system when something happens, such as a shipment being shipped or an inbound being checked, so you don't have to poll the API. You register a URL for an event, and Paxon sends an HTTP POST request to that URL every time the event occurs.
How it works
- Subscribe. Register a webhook with
POST v3/webhooks: one webhook per event, with thetargetUrlthat should receive it. The available events are listed under Events. - Receive. When the event occurs, Paxon sends a
POSTrequest with a JSON body to yourtargetUrl. - Verify. Your endpoint checks the signature to confirm that the request comes from Paxon and was not changed on the way.
- Acknowledge. Your endpoint responds with a
2xxstatus code within 15 seconds. - Process. Your system processes the event, preferably after it has responded.
{
"data": {
"type": "webhook",
"attributes": {
"event": "shipment.shipped.3",
"isActive": true,
"targetUrl": "https://example.com/webhooks/shipment/shipped"
}
}
}
Use PUT v3/webhooks/{id} with isActive: false to pause a webhook, and DELETE v3/webhooks/{id} to remove it. The targetUrl must be reachable from the internet over HTTPS.
The request
Each delivery is an HTTP POST with Content-Type: application/json.
| Header | Description |
|---|---|
X-Event-Id | Unique identifier (UUID) of the event. It is the same for every delivery attempt of that event, so use it to detect duplicates. |
X-Hook0-Signature | Signature to verify that the request comes from Paxon. See Verifying the signature. |
The body follows the same layout as the response of the corresponding GET endpoint: the resource is in data, and related resources are in included at the top level. Some events add attributes.timestamp, the date and time (UTC) at which the event occurred. The payload of each event is described under Events.
Delivery behaviour
In short, the webhook engine works as follows:
- At least once. Every event is delivered at least once, and sometimes more than once.
- No guaranteed order. Events are sent as they occur, but they can arrive in a different order, especially after a retry.
- Status code only. Only the HTTP status code of your response counts. Any
2xxis a success; everything else is a failure. - 15 seconds. A response that takes longer than 15 seconds counts as a failure.
- Retries. A failed delivery is retried with increasing intervals, for up to 24 attempts or 8 days.
- Resending. After the last attempt the event is not delivered again automatically. For some event types Paxon can resend events on request; for others this isn't possible.
Responding
Paxon only looks at the HTTP status code of your response. The body is ignored.
| Your response | Result |
|---|---|
Any 2xx, for example 200 OK, 202 Accepted or 204 No Content | Delivered. |
4xx, including 400, 401, 404 and 410 | Failed, retried. |
429 Too Many Requests | Failed, retried. If you send a Retry-After header, the next attempt waits at least that long. |
5xx | Failed, retried. |
| No response within 15 seconds | Failed, retried. |
| Connection, DNS or TLS error | Failed, retried. |
A 4xx is not treated as a permanent rejection: the event is retried like any other failure. If you don't want an event any more, deactivate or delete the webhook instead of rejecting its deliveries.
Respond first, process later. Store the event (for example in a queue or table), return 202 Accepted, and process it in the background. Slow processing is the most common cause of timeouts, and every timeout leads to the same event being delivered again.
Retries
A failed delivery is retried with increasing intervals. The waiting time before each next attempt is:
| After failure | Next attempt after |
|---|---|
| 1 | 3 seconds |
| 2 | 10 seconds |
| 3 | 3 minutes |
| 4 | 30 minutes |
| 5 | 1 hour |
| 6 | 3 hours |
| 7 | 5 hours |
| 8 and later | 10 hours |
A small random delay is added to each interval. Retries stop after 24 attempts or 8 days, whichever comes first. After that the event is not delivered again automatically.
Paxon can resend missed events on request for some event types, but not for all of them. Don't rely on resending: make sure your endpoint is available, and use the GET endpoints to catch up on the current state of orders, shipments and inbounds after an outage.
Because of retries, the same event can arrive more than once, and events can arrive in a different order than they occurred.
Duplicates and ordering
- Duplicates. Every attempt of the same event carries the same
X-Event-Id. Store the ids you have processed and skip an event whose id you have already seen. Keep them for at least 8 days, the length of the retry window. - Ordering. Don't rely on the order in which requests arrive. Use the
attributes.timestampof the event, or the state of the resource itself, to decide which information is the most recent. When in doubt, retrieve the current state with the correspondingGETendpoint.
Verifying the signature
The X-Hook0-Signature header has three parts, separated by commas:
X-Hook0-Signature: t=1765443663,h=content-type x-event-id x-event-type,v1=85da0586ae0b711d...
| Part | Description |
|---|---|
t | Unix timestamp (seconds) at which the request was signed. |
h | Space-separated names of the request headers that are included in the signature, in order. |
v1 | HMAC-SHA256 signature, hex-encoded. |
To verify a request:
- Split the header into
t,handv1. - Take the values of the headers listed in
h, in the same order, and join them with.. - Build the signed string:
{t}.{h}.{header values}.{raw request body}. - Compute the HMAC-SHA256 of that string with the secret key of your webhook, and hex-encode it.
- Compare the result with
v1using a constant-time comparison. - Reject the request if
tis more than 5 minutes away from the current time, to prevent replays.
Always use the raw request body exactly as received. Parsing and re-serializing the JSON changes it, and the signature won't match.
const crypto = require('crypto');
const express = require('express');
const app = express();
const secret = process.env.PAXON_WEBHOOK_SECRET;
app.post('/webhooks/shipment/shipped', express.raw({ type: 'application/json' }), (req, res) => {
const parts = Object.fromEntries(
req.get('X-Hook0-Signature').split(',').map((part) => part.split(/=(.*)/s).slice(0, 2))
);
const headerNames = parts.h.split(' ');
const headerValues = headerNames.map((name) => req.get(name) ?? '').join('.');
const signed = `${parts.t}.${parts.h}.${headerValues}.${req.body.toString('utf8')}`;
const expected = crypto.createHmac('sha256', secret).update(signed).digest('hex');
const valid =
expected.length === parts.v1.length &&
crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) <= 300;
if (!valid || !fresh) {
return res.sendStatus(401);
}
// Store the event for processing, then respond quickly.
queue.push({ id: req.get('X-Event-Id'), body: JSON.parse(req.body) });
res.sendStatus(202);
});
Checklist
- Use an HTTPS
targetUrlthat is reachable from the internet. - Verify the signature of every request and reject requests older than 5 minutes.
- Respond with a
2xxwithin 15 seconds, and process the event afterwards. - Detect duplicates with
X-Event-Id. - Order events by their timestamp, not by their arrival.
- Deactivate or delete webhooks you no longer need instead of rejecting their deliveries.