A webhook sends your server a JSON POST when something happens on your site. Use it to feed a CRM, a fulfilment system or an automation tool.
Set one up
- In the Studio, open Connections and find Event connectors.
- Add a Webhook and enter your POST URL, with an optional Signing secret. If you leave it empty, one is generated for you.
- Send a test before relying on it.
Webhook connectors cover order.placed, order.paid and form.submitted. The body contains event, site, at (milliseconds) and data.
Headers
| Header | Meaning |
|---|---|
x-xigzag-event | Event name |
x-xigzag-site | Site id |
x-xigzag-delivery-id and idempotency-key | Stays the same across retries |
x-xigzag-timestamp | Unix time in seconds |
x-xigzag-signature | sha256= followed by the HMAC |
Verify the signature
Compute HMAC-SHA256 over the timestamp, a dot and the raw body, using your signing secret. Reject deliveries more than 300 seconds old.
import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(secret, rawBody, headers) {
const t = headers["x-xigzag-timestamp"];
if (!(Math.abs(Date.now() / 1000 - Number(t)) <= 300)) return false;
const want = Buffer.from("sha256=" + createHmac("sha256", secret).update(t + "." + rawBody).digest("hex"));
const got = Buffer.from(headers["x-xigzag-signature"] || "");
return want.length === got.length && timingSafeEqual(want, got);
}Good practice
- Verify against the raw request body, before parsing it.
- Store delivery ids and ignore ones you have already handled.
- Give the final URL. Redirects are not followed.
- Respond quickly with a success status and do slow work afterwards.
