Webhooks
Receive signed activity deliveries and reconcile them safely.
Create one or more endpoints with POST https://tickets.lissen.com/api/v1/webhook_endpoints. Each endpoint has an HTTPS URL, a status, metadata and the activity types it receives. enabled_types accepts exact names such as order.paid, a resource wildcard such as order.*, or *.
The create response includes secret once. Save it immediately. Later reads, lists and updates never return it. Use POST /v1/webhook_endpoints/{id}/rotate to mint a replacement.
const endpoint = await client.createWebhookEndpoint({
idempotencyKey: crypto.randomUUID(),
body: {
url: "https://partner.example/webhooks/ticketing",
enabled_types: ["order.*", "refund.*"],
},
});Verify signatures
Every request body is the same activity envelope returned by GET /v1/activities/{id}. Verify the raw request bytes before parsing JSON. Ticketing-Signature has a Unix timestamp and one or more v1 HMACs.
import { createHmac, timingSafeEqual } from "node:crypto";
function verify(rawBody: Buffer, header: string, secret: string) {
const values = Object.fromEntries(header.split(",").map((part) => part.trim().split("=")));
const timestamp = values.t;
if (!timestamp || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const expected = createHmac("sha256", secret)
.update(Buffer.concat([Buffer.from(`${timestamp}.`), rawBody]))
.digest("hex");
return header.split(",").some((part) => {
const value = part.trim();
const signature = value.startsWith("v1=") ? value.slice(3) : "";
// Validate attacker-controlled text before a length-sensitive compare.
if (!/^[0-9a-f]{64}$/iu.test(signature)) return false;
return timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(signature, "hex"));
});
}Rotation keeps the old secret active for 24 hours. During that overlap, requests contain multiple v1 values. Accept a match for either your old or new secret until the overlap has elapsed.
Delivery and recovery
Any 2xx response accepts a delivery. Failed deliveries retry at roughly 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, then every 12 hours, for up to three days. There is no ordering guarantee and you may receive the same act_ id more than once. Store and deduplicate by act_ id.
Run a daily reconciliation request even when your endpoint is healthy. At the
start of a pass capture T; query GET /v1/activities from your stored
watermark minus a generous overlap (48 hours is a sensible nightly margin),
page the entire result with no persistent cursor, and apply every activity
idempotently. Only after the whole pass commits locally, advance the watermark
to T — never to the newest activity you happened to observe. A later pass
then covers activities that committed after the pass began.
If an endpoint is disabled after repeated failures, fix it, update its status to enabled, then run this reconciliation process to close the gap.