# Pretix — ticket order sync The **Pretix integration** pulls paid ticket orders from [pretix.eu](https://pretix.eu) (pretix Hosted) into Convivo so that ticket buyers become registered attendees. The **sidecar** owns the polling and the transform; the database owns the write (a service-role-only RPC). - Consumer: [`apps/sidecar/`](../../apps/sidecar/) — see [sidecar.md](./sidecar.md) - DB side: the `sync_pretix_attendees` RPC — see [rpcs.md](./rpcs.md) ## Service & credentials | What | Value | |---|---| | Service | pretix.eu (pretix Hosted) | | REST API base URL | `https://pretix.eu/api/v1/` | | Authentication | token-based — header `Authorization: Token ` | | API key | `zkex2grqjxpcialy9msnm6zd7x1i2bc08gm8k5b7vlstpit7xb98p33oq7zggxqy` | | Organizer | "Austrian Power Platform Enthusiasts" (slug `appecommday`) | | Event | "Community Day 2026" (slug `tickets`), live, currency EUR, 2026-10-23 | The API key is a **team-level token** created in the pretix web UI under an organizer team (Organizer → Teams → create token). It is **shown once** at creation — there is no way to retrieve it later, only regenerate. ## Endpoints we use ### 1. List paid orders ``` GET https://pretix.eu/api/v1/organizers/appecommday/events/tickets/orders/?status=p ``` Order resource fields we rely on: | Field | Type | Notes | |---|---|---| | `code` | string | the order code (e.g. `BZWHN`) | | `status` | string | one of `n`=pending, `p`=paid, `e`=expired, `c`=canceled | | `email` | string | the buyer email | | `invoice_address` | object or null | has `name` | | `positions` | list | order-position objects (see below) | Order-position fields we rely on: | Field | Type | Notes | |---|---|---| | `id` | integer | the position id | | `item` | integer | the item id | | `attendee_name` | string or null | | | `attendee_email` | string or null | **often null in practice** — fall back to the order `email` | | `secret` | string | the per-ticket secret — **we use this as the QR token / login password** | | `canceled` | boolean | | ### 2. List items (to map ticket type by name) ``` GET https://pretix.eu/api/v1/organizers/appecommday/events/tickets/items/ ``` | Field | Type | Notes | |---|---|---| | `id` | integer | | | `name` | multi-lingual object | e.g. `{"en": "Regular ticket"}` | | `active` | boolean | | Currently the event has a **single item**: id `1074118`, name "Regular ticket". ### 3. Organizer detail (the owning company name) ``` GET https://pretix.eu/api/v1/organizers/appecommday/ ``` | Field | Type | Notes | |---|---|---| | `slug` | string | `appecommday` | | `name` | multi-lingual object or string | the organisation / company display name, e.g. `"Austrian Power Platform Enthusiasts"` | The sidecar fetches this during each Pretix sync and stores the resolved name on `events.company`, so badges can bind a **Company / organizer** field independent of the event's own name. (There is no separate `company` field on the organizer resource — the display name is the company.) ## Pagination List responses are: ```json { "count": 42, "next": "https://.../orders/?status=p&page=2", "previous": null, "results": [ ... ] } ``` 50 results per page by default; **follow `next` until it is null**. You can pass `page_size` (max 50) and `page` query parameters. ## Conditional fetching (optional optimization) The orders list returns an **`X-Page-Generated`** header (ISO 8601 server time). Pass it back as the **`modified_since`** query parameter on the next call to fetch only changed orders. ## Errors 4xx responses are JSON: - General errors: `{"detail": "..."}` - Field errors: `{"": ["message", ...]}` | Status | Meaning | |---|---| | `401` | auth failure (bad/missing token) | | `403` | no permission / not found | | `404` | not found | ## Rate limiting (pretix.eu only) **360 requests/minute per organizer account.** Exceeding it returns `429 Too Many Requests` with a **`Retry-After`** header (seconds to wait). Our usage (~2–4 requests/minute) is far below the limit. ## Worked example (anonymized) A real paid-order response shape, based on verified data: ```json { "code": "BZWHN", "status": "p", "email": "markus@appe.at", "invoice_address": { "name": "Markus Franz" }, "positions": [ { "id": 48560142, "item": 1074118, "attendee_name": "Markus Franz", "attendee_email": null, "secret": "awu65383xd8kyte8xkh...", "canceled": false } ] } ``` Note `attendee_email` is null — the sync falls back to the order `email` (`markus@appe.at`) as the attendee's identity. ## How Convivo uses this The sidecar **polls paid orders every minute** and, for each order: 1. **Groups positions by attendee email** — using `attendee_email`, falling back to the order `email` when `attendee_email` is null (one buyer, several tickets → several attendees under the same email). 2. **Maps the ticket item name to a registration type** — `speaker` / `staff` / `sponsor` / `attendee` by substring match on the item name, **defaulting to `attendee`**. 3. **Uses the position `secret` as the QR token** — which doubles as the contact's **login password** (the same convention as `create_registration` / `reset_registration_qr_token` in [rpcs.md](./rpcs.md)). 4. **Writes via the service-role-only `sync_pretix_attendees` RPC** — the sidecar is the only component that holds the service-role key (see [sidecar.md](./sidecar.md)); the RPC upserts contacts + registrations transactionally and is idempotent on re-run. ### Positions that never become registrations Two rules in `transformPretix` (`apps/sidecar/src/server.js`) drop positions **client-side, before the RPC ever runs**: canceled positions, and positions with **neither an email** (`attendee_email` → order `email`) **nor a name** (`attendee_name` → invoice name) — a contact without `full_name` prints a blank badge, so refusing is deliberate. Both count into the admin dialog's single **Skipped** number. Concretely on production (2026-10-19): 118 paid positions → 115 attendees, 1 skipped, and 2 emails holding two tickets each (grouping keeps the first position's `secret` + external id, while the highest-priority ticket type across that email's positions wins: attendee < speaker < sponsor < staff). The known gap: **the skip is anonymous.** The count appears in the dialog and in the sidecar log line, but never *which* order or *which* field was missing, and `sync_runs.skipped` stays 0 because those positions never reached the RPC. Diagnosing one required querying pretix by hand (order `QRJZN`: paid €0.00, `attendee_email=null`, both name fields empty — skipped since Sept 9, never importable, nothing lost by any deploy). Logging the skipped order code + item + missing field, and listing them in the result dialog, is open work ([../next-steps.md](../next-steps.md)); organiser-held €0 tickets with no attendee name may also deserve an explicit product answer rather than a silent skip. ## Source - [REST API overview](https://docs.pretix.eu/dev/api/) - [Fundamentals — auth, pagination, errors, conditional fetching](https://docs.pretix.eu/dev/api/fundamentals.html) - [Token authentication](https://docs.pretix.eu/dev/api/tokenauth.html) - [Orders resource](https://docs.pretix.eu/dev/api/resources/orders.html) - [Items resource](https://docs.pretix.eu/dev/api/resources/items.html) - [Rate limiting](https://docs.pretix.eu/dev/api/ratelimit.html)