# Qruuk webhooks Register an https endpoint (create_webhook tool, or Settings → Webhooks) and choose events: - `card.issued` - `stamp.added` - `reward.earned` - `reward.redeemed` - `ticket.used` - `entry.recorded` - `customer.opted_in` - `customer.unsubscribed` - `order.paid` - `order.refunded` - `membership.started` - `membership.renewed` - `membership.stopped` - `session.booked` - `session.booking_cancelled` - `session.checked_in` - `session.check_in_undone` - `session.no_show` - `session.cancelled` - `session.waitlist_joined` - `session.waitlist_offered` - `session.waitlist_taken` Session events — classes and events with sign-up alike — come once per person, with the attendee and the session (`attendeeId`, `name`, `status`, `method` self|staff|purchase|free, `session: { id, title, startsAt, endsAt, location, capacity, programId, seriesId }`) and, when they have them, the card, its program and the customer: - `session.booked`, `session.booking_cancelled` (`by`: customer|staff) - `session.checked_in` (`used`: visit|ticket|null), `session.check_in_undone` - `session.no_show`: a booking nobody came for, sent by the daily sweep afterwards - `session.cancelled`: the class or event was cancelled, one event for each person booked or in - `session.waitlist_joined` (`waitlistId`, `position`, `email`): someone joined the waitlist of a full class - `session.waitlist_offered` (`waitlistId`, `email`, `offerExpiresAt`): a place given back is held for the first in line, who got the link by email - `session.waitlist_taken` (`waitlistId`): they took it; it is now their booking (`session.booked` comes too) Each delivery is a POST with JSON: ```json { "id": "delivery id", "type": "stamp.added", "createdAt": "ISO time", "accountId": "…", "data": { "code": "…", "productType": "pass", "customerId": "…" } } ``` Headers: `Qruuk-Event`, `Qruuk-Delivery` (idempotency — the same delivery can arrive twice), `Qruuk-Signature: t=,v1=`. Answer 2xx within 8 s. Failed deliveries are retried; see list_webhook_deliveries for the log. ## Verify the signature v1 = HMAC-SHA256(endpoint secret, "."), hex. Compare in constant time; reject t older than 5 minutes. ```ts async function verify(secret: string, header: string | null, raw: string): Promise { const m = header?.match(/^t=(\d+),v1=([0-9a-f]+)$/); if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return false; const key = await crypto.subtle.importKey('raw', new TextEncoder().encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']); const sig = new Uint8Array(await crypto.subtle.sign('HMAC', key, new TextEncoder().encode(`${m[1]}.${raw}`))); const hex = [...sig].map((b) => b.toString(16).padStart(2, '0')).join(''); if (hex.length !== m[2].length) return false; let diff = 0; for (let i = 0; i < hex.length; i++) diff |= hex.charCodeAt(i) ^ m[2].charCodeAt(i); return diff === 0; } ``` ```python import hmac, hashlib, time def verify(secret: str, header: str, raw: bytes) -> bool: parts = dict(p.split("=", 1) for p in header.split(",")) if abs(time.time() - int(parts["t"])) > 300: return False expected = hmac.new(secret.encode(), f"{parts['t']}.".encode() + raw, hashlib.sha256).hexdigest() return hmac.compare_digest(expected, parts["v1"]) ```