Files
Convivo/docs/backend/pretix.md
T
Lago b7c2abb73b docs: seed drift, pretix skip observability, new-suite run books, current-state refresh
tests.md: new 'Full E2E Suite Status' opener -- suite is NOT green (213/42,
2026-10-19, exit 1); the pipe-through-tail trap that produced two false '0
failed' records; seed-drift mechanism (config.ts identities gone, reset.ts
UPDATE-only no-ops, logins hang); 11 failing families; admin-schedule
exonerated by the reverted-Schedule.tsx check; fix direction (upsert demo
identities, self-provision new specs). Four new run sections: llm-connection
(three-state verdict), tooltip containment (mutation-validated provenance),
CONV-MATERIAL-005 (self-contained fixture pattern), corrected counts
(sidecar 35, checkin-points 4).

pretix.md: 'Positions that never become registrations' -- the email+name
guard, the 118->115 grouping on production numbers, and the anonymous-Skipped
gap (QRJZN case study, sync_runs.skipped never sees client-side drops).

next-steps.md: new 'Known work (open as of 2026-10-19)' section (seed drift,
skip observability, QRJZN operator action); stale cross-cutting items marked
done (subdomains live, printing shipped after the 'skipped by decision'
note, testing exists); Open decisions cleared; current-state blockquote
extended through the 2026-10-19 round.
2026-10-19 22:39:23 +02:00

198 lines
7.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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>` |
| 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: `{"<field>": ["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": "[email protected]",
"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`
(`[email protected]`) 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)