Developers

Scanner API

How devices authenticate and admit tickets.

The scanner API is device-agnostic: the PWA, a tablet, and the Raspberry Pi reader all speak the same three calls. A device authenticates with its gtscan_… key, exchanges it for a short-lived token, then validates and admits tickets.

1 — Authenticate

Exchange the device key for a JWT. The response includes the device's label and allowed zones.

POST /api/scanner/auth
{ "apiKey": "gtscan_…" }
→ { "token": "…", "scanner": { "label": "gen", "zones": [0] } }

2 — Scan (preview, read-only)

Validate a scanned QR without admitting — useful for a preview screen.

POST /api/scanner/scan
Authorization: Bearer <token>
{ "payload": "<ticketId:ts:hmac>" }
→ { "valid": true, … }

3 — Activate (admit + burn)

Admit the holder. This validates the rotating QR, checks the device's event/zone scope, and marks the ticket used. Open the door on success.

POST /api/scanner/activate
Authorization: Bearer <token>
{ "payload": "<ticketId:ts:hmac>" }
→ { "success": true, "zoneName": "General Admission", "zoneColor": "#6366F1" }
A second activation of the same ticket returns 409 Already activated — the built-in double-scan guard. Canceled / refunded tickets and canceled or ended events return 403 with { valid: false, reason }. 423 with heldBy means another gate holds this ticket's offline entry right and cannot be reached — send the guest there.

4 — Offline mode (optional)

A device that should keep admitting without network keeps a snapshot and a heartbeat. Each ticket's offline entry right belongs to ONE device, and only that device receives the ticket's QR key — so two offline gates can never both admit the same ticket.

GET /api/scanner/snapshot          (every 60 s)
X-Offline-Protocol: 2
→ { leaseSeq, tickets: [{ id, own, qrSeed (own only), holder, activated, … }] }

POST /api/scanner/offline/heartbeat (every 3 s)
{ "released": [ticketIds you dropped], "since": serverTime }
→ { seq, release: [ticketIds to drop now], stale, used: [{ id }], serverTime }

POST /api/scanner/sync              (door decisions taken offline)
{ "decisions": [{ clientId, ticketId, verdict: "admit", scannedAt }] }

Each event in the snapshot carries endsAt (the end rule's answer). Offline, refuse every admit once now + clockSlackS reaches it — the entry QR expires with the event. The sync answers an admit stamped after the end with status: "conflict", reason: "event_ended"; one taken before the end and synced later is applied. Events that have ended or were canceled are no longer in the snapshot at all.

Offline, admit only tickets with own: true. When the heartbeat lists a ticket under release, drop it, sync any offline admit of it first, then acknowledge it in the next heartbeat. Refuse a snapshot whose leaseSeq is lower than the last seq you received. After an online admit (or a 409), and for every ticket in used, mark the ticket used locally — otherwise your door could admit it again once offline.