# Concepts

> The few things the rest of the docs assume: organizations, modes, events, bundles, holds, orders, tickets and the event log

Source: https://rcms-tickets-test.web.app/docs/concepts

## Organizations and modes

An **organization** owns everything: events, orders, tickets, keys, the team. An API key belongs to one. Inside it, every record lives in one of two **modes**, `test` and `live`, which never mix. Every resource carries `mode`, and an id from one mode is not found in the other.

## The shape of the API

- JSON in and out, with `snake_case` field names. Every resource has an `object` field that names its kind.
- **Money** is `{ amount, currency }`, with `amount` an integer in the currency's smallest unit (`5000` is $50.00). Never a float.
- **Dates** are `YYYY-MM-DD` and never shift a day. **Instants** are ISO 8601, answered in UTC.
- **Ids** are a prefix and about 20 characters: the prefix tells you the kind.

| Prefix | Is |
| --- | --- |
| `evt_`, `day_` | An event, and one of its days |
| `tt_`, `add_`, `code_` | A ticket type, an add-on, a promo or access code |
| `hold_` | A reservation with a price and a clock |
| `ord_`, `pay_`, `rfd_`, `exc_` | An order, a payment, a refund, an exchange |
| `tkt_`, `trf_` | A ticket, a transfer |
| `chk_`, `dev_`, `dsl_` | A check-in, a door device, a gate sale |
| `whe_`, `whd_`, `log_` | A webhook endpoint, a delivery, a row of the event log |
| `key_`, `org_`, `mem_` | An API key, an organization, a member |

- **Lists** answer `{ object: "list", data, has_more, url }`, newest first, and take `limit` (1 to 100) and `starting_after`.
- **Errors** answer `{ error: { type, code, message, param, doc_url, request_id, decline_code } }`. Match on `code`. Quote `request_id` to support. [Errors](https://rcms-tickets-test.web.app/docs/errors.md).

## Events, days and what is for sale

An **event** (a festival, a show) has **days**, each with doors, a start and an end in the venue's timezone. It sells **ticket types** (kinds of admission with a price, fees, capacity, the days they are good for, a sale window and limits) and **add-ons** (extras sold per order, like parking, or per ticket, like a drink package). A **code** is a discount, a key that unlocks hidden types, or both.

A type or add-on is good for all days (`valid_days: "all"`, the default) or for days you name. "All days" means every day the event has, a day added later too, so adding a day gives it to every all-days ticket already sold or held, and the new day's capacity starts with them. While any are out, `POST /v1/events/{id}/days` asks you to say so with `extend_sold: true`, and refuses without it, saying how many and of which types. For a second show sold on its own, copy the event (`POST /v1/events/{id}/copy`) instead. A day can be removed again while nothing but those all-days tickets ties to it: no type or add-on names it, and nobody was scanned or sold to at the door on it. That takes the day off tickets people paid for, and no money moves, so while any are sold or held `DELETE /v1/events/{id}/days/{day}` asks you to say so with `remove_from_sold=true`. If buyers are owed money for the day, refund them, or postpone the day to a new date instead: their tickets move with it, and they can ask for their money back until a deadline.

An event is a `draft`, `on_sale`, `paused`, `ended` or `cancelled`. Nothing is for sale until you publish it. An on-sale event ends by itself a day after its last day's end. A person can't undo `ended`, with one exception: when the hourly sweep ended it, say a wrong year on the date, an owner or admin has 30 days (`reopen_until`) to `POST /v1/events/{id}/reopen`, which brings it back to `paused` to fix its days. An event a person ended stays ended. A paused event never ends by itself: it stays paused, taking no new holds, until a person changes its days, ends it or cancels it. A hold made before the pause can still be paid for until its time runs out, at the price it was held at. A cancelled event refuses it. Resuming a paused event whose last day has passed is refused (`invalid_state_transition`), because it would soon end by itself: change its days first, or end it. A change that puts a day with tickets out in the past is refused unless it says `confirm_past: true`. Stock is exact: a hold takes it, and it cannot be sold twice.

## When the time or place changes

Change a day's date, doors or start, make its end earlier, or give the event a new venue name or street address, and each holder of a ticket it touches is told, whether the change came from the dashboard, the API or an agent:

- **One message, a little later.** The email goes about 10 minutes after the change, with the old and new facts. Another change in that time waits with it, so fixing a typo twice is still one email. Put it back and nothing goes. A buyer who agreed to texts also gets a text. A message goes at most 3 times per event in 24 hours: past that the change is still saved at once, and its message goes when the allowance is back.
- **Only what a guest must act on.** A later end, a day's name or capacity, a postal code, a map pin or the same address spelled differently tell nobody. A new time zone counts only if it moves the clock people read. Adding a day tells nobody. Removing a day tells the holders of tickets for all days who knew of it: they bought while it was there, or a message since told them. So a day added by mistake and removed again before anyone bought with it tells nobody. `notify=false` removes a day quietly.
- **Only people it touches.** A holder hears about the days of their own tickets. An order bought after the last change bought the new facts, and hears nothing. An event with no orders tells nobody, so a correction before any ticket is out is free.
- **`notify: false`** on the `PATCH` keeps that change quiet, also while a notice about an earlier change is waiting: that notice still goes, with its own news and without this change. The one exception is a day or a place that notice is already about: holders read how it stands now, because we never send a time or place that is no longer true. It doesn't call back a waiting notice: to stop one, put the facts back. The ticket page and the Wallet pass show every change. An event with our emails switched off gets no email either, as with every other message, and `change_notice` says so (`not_sent_why: "emails_off"`). An order with its own emails off, or an erased buyer, is simply left out: if nobody else was told, `not_sent_why` is `nobody_to_tell`.
- **A comp or a gate sale's holder is told whichever way we can use then**, whether or not their tickets went at the start: the "Send the tickets" switch is about the tickets, not news of a cancelled show. On an order you made with `POST /v1/orders`, `notify: { email: false }` means you tell your own buyers, and we stay quiet.
- **A holder with only a phone number** is told by text, where texts are on and the org allows the number's country, for a new time or place, a postponement and a cancellation alike. Someone we can't reach is counted: `unreachable` on `change_notice`, `holders_unreachable` in the job's `result`.
- **`change_notice` on the event** says what will go and when (`pending`, with `send_at`), then that it went (`sent`, with `emails` and `texts`), or that nothing went (`not_sent`, and `not_sent_why` says why). Ending sales on a show still to come doesn't stop a notice that is waiting. The change itself is an `event.updated` webhook at once. Wallet passes update by themselves.

To move dates and offer refunds as well, use `POST /v1/events/{id}/postpone`.

## Bundles

A **bundle** is one purchase that issues several tickets: a 5-pack. Give the ticket type `tickets_per_unit: 5`, and a quantity of 1 is one bundle.

- `price` is for the whole bundle.
- `capacity` counts tickets, so a 5-pack with a capacity of 50 sells 10 bundles.
- `per_order_min` and `per_order_max`, on the ticket type, count bundles. `settings.max_tickets_per_order`, on the event, counts tickets. Both apply.
- Availability counts bundles: `remaining` (given only when `low` or sold out) is whole bundles, and `low` is judged on the seats left, as for any type: 10 or fewer, or 10% of capacity, whichever is more. A 5-pack with a capacity of 50 starts out `available`, and reads `low` at 10 tickets left, with `remaining: 2`.
- Each ticket is its own ticket at the door. The buyer holds all of them and passes them on.

```ts
const fivePack = await tickets.ticketTypes.create({ event, name: 'Five-pack', price: { amount: 20000, currency: 'usd' }, tickets_per_unit: 5, capacity: 50 });

const heldPack = await tickets.holds.create({ event, items: [{ ticket_type: fivePack.id, quantity: 1 }] });
const boughtPack = await tickets.orders.create({ hold: heldPack.id, buyer: { name: 'Maria Delgado', email: 'maria@example.com' }, payment: { provider: 'test', token: 'tok_success' } });

const packTickets = (await tickets.orders.retrieve(boughtPack.id)).tickets;
console.log(heldPack.price.subtotal.amount, packTickets.length); // 20000 5
```

## Hold, order, ticket

1. A **hold** reserves items for a short time (10 minutes by default) and answers the **price breakdown**: the only price you may show or charge.
2. An **order** turns the hold into a sale with its payment. The hold is used exactly once.
3. The order issues **tickets**, one per admission. A ticket has a holder, a **version**, a signed **QR code**, a private page, and Wallet links.

The ticket's **version** goes up when its QR code must change: a transfer, a reissue, an exchange. A QR code made for an older version stops working at the door (`not_valid`, reason `transferred` or `reissued`).

### What one network may hold

A hold costs nothing, so one network (one IPv4 address, or one IPv6 /48) may hold at most half of what's left of each pool, in tickets, bundles in full, and always enough for a family of 4. It holds for every hold that names `attribution.client_ip`, whatever site made it. On a live key, a hold with no address counts as the key's one network, unless an owner marked the key `sells_from_one_address`.

Tickets that are only held are never called sold out. Availability says `held: true`, and a hold answers 429 `rate_limited`, with `param` `items`, or `items[n].quantity` when fewer would fit.

A hold can name the one it `replaces`, a hold of that same network on that event: its tickets don't stand in the way of the new one's share, and it is let go once the new one exists.

During an attack, an owner, an admin or a full key can see who holds the most with `GET /v1/events/{id}/hold_networks` (hashed, no addresses), and let one go with `POST /v1/events/{id}/hold_networks/release`. It takes a `dry_run`, gives that network only "busy" for an hour unless `block_minutes` says otherwise, leaves an audit row, and never touches an order. A venue's wifi can look like an attack, so read the list first.

## Refunds, transfers, exchanges

After the sale, the buyer's money and the ticket can change: a [refund](https://rcms-tickets-test.web.app/docs/refunds.md) gives money back and voids tickets, a [transfer](https://rcms-tickets-test.web.app/docs/transfers.md) moves a ticket to someone else, an [exchange](https://rcms-tickets-test.web.app/docs/exchanges.md) upgrades or swaps without a refund and a rebuy. Each is its own resource, and each changes the order.

## The event log

Nearly every state change in your organization is a row of the **event log** (`order.paid`, `ticket.checked_in`, `hold.expired`…). [Webhooks](https://rcms-tickets-test.web.app/docs/webhooks.md) are the log delivered to you, and `GET /v1/event_log` lets you read it. The log is how you stay in step without polling: it is the one place that says what changed, when, who did it and which request. [The event types](https://rcms-tickets-test.web.app/docs/events.md). A row holds the resource as it was, including what opens a ticket, so treat rows and webhook bodies as secrets ([what a body carries](https://rcms-tickets-test.web.app/docs/webhooks.md#rules-for-the-receiver)).

## Where a sale came from

A hold can carry where the buyer came from (UTM tags, click ids, the ad cookies), and the order keeps it. [Tracking and pixel dedup](https://rcms-tickets-test.web.app/docs/tracking.md) says what is captured and how to use it.

## Finding an order or a ticket

`POST /v1/orders/search` and `POST /v1/tickets/search` take what a person gave in `q`, in the body so it stays out of URLs and logs:

- An **email** (it has an @) or a **phone** matches exactly. An **order number** finds that order, or all of its tickets. A **ticket code** finds that ticket.
- Anything else is a **name**. It matches the start of the whole name, or the start of any word of it. "Mar", "Maria", "Delgado", "del" and "Maria Del" all find Maria Delgado. Case and accents do not matter. Every word you type has to start a word of the name.
- A word of 2 letters finds a name that starts with it, or a name with that whole word ("Li" finds Lisa Ray and Wei Li).

A name search lists in name order. The door has its own look-up with the same name rule, `POST /v1/checkins/lookup`.

## Who can do what

An API key has a **scope**: `full`, `read` or `checkin`. A person has a **role**: owner, admin, staff, door or viewer. A door phone has a device token. A holder has a private link. [Authentication](https://rcms-tickets-test.web.app/docs/authentication.md).
