# The booking flow

Step by step from the first screen to the confirmation, for a salon and for a restaurant.

All calls go to `https://www.callyndar.com/api/v1` with the header `Authorization: Bearer cal_pk_live_YOUR_KEY`. Dates are `YYYY-MM-DD`, times `HH:MM`, always in the venue's time zone (`venue.timezone`). Show price and duration only as the API returns them.

## 0. Load the venue

`GET /venue` tells you which flow you are building:

| `venue.booking_mode` | Sector | Flow |
|---|---|---|
| `services` | salon, barber, clinic | services → (variant) → staff member or "no preference" → day → time |
| `party_size` | restaurant (and others) | party size → day → time |

Also keep `venue.booking` (rules), `venue.privacy_url`, `venue.terms_url`, `venue.turnstile_site_key` and `venue.turnstile_required`.

## Salon variant

### 1. Services and variants

`GET /services` returns `categories` (with `parent_id`, for a tree) and `services`. Per service:

- `duration_minutes`, `price_cents` (`null` = the venue hides the price; show nothing or `price_note`), `deposit_cents`.
- `variants`: choices such as "short / medium / long", each with its own duration and price.
- `duration_min_minutes`, `duration_max_minutes`, `price_from_cents`: what to show in your list. With variants, the shortest and longest duration and the lowest price ("30–60 min · from € 35"; one value when they are equal); otherwise the service's own values. Don't show the service's base duration and price next to variants.
- `variant_mode`:
  - `"customer"`: let the guest choose a variant (`variant_question` and `help_text` help with that).
  - `"staff"`: the venue decides later. The guest chooses nothing; you send the service along in `pending_ids`.
  - `null`: no variants.
- `allow_service_combos`: `false` means one service per booking.
- `required_providers`: how many staff members the service needs at the same time (usually 1). With 2 or more it is a **duo treatment**: you always book it on its own (never together with other services, otherwise `422 invalid_input` with `reason: "multi_staff_combo"`) and the venue assigns the extra staff members.

You send the selection along in every following call in the same way:

- `service_ids`: the chosen services, in the order they were chosen.
- `variant_ids`: per position in `service_ids` the chosen variant, or `null`. In a query string: comma-separated with empty slots, e.g. `variant_ids=aaa,,bbb`.
- `pending_ids`: the services with `variant_mode: "staff"`.

The server always calculates the appointment duration itself from this selection.

### 2. Staff member

`GET /providers?service_ids=<id>,<id>` returns the staff members who can do **all** chosen services. Always show the option **"No preference"** as well: in that case you send no `provider_id` and Callyndar picks the first free staff member.

### 3. Day

`GET /calendar?from=2026-12-01&to=2026-12-31&provider_id=<id>` (max. 92 days) returns per day `open: true|false` with a `reason`:

| `reason` | Meaning |
|---|---|
| `past` | in the past |
| `weekly_closed` | regular closing day |
| `online_day_disabled` | open, but not bookable online |
| `holiday` | public holiday or closure (`message` = label) |
| `day_block` | the venue blocked the day (`message` = the owner's message, show it) |
| `beyond_max_advance` | further out than the venue allows online booking |
| `provider_leave` | the chosen staff member is on leave |
| `provider_not_working` | the chosen staff member does not work that day (schedule) |

### 4. Time

`GET /availability?date=2026-12-04&service_ids=<id>&variant_ids=<id>&provider_id=<id>` returns `slots`:

```json
{ "date": "2026-12-04", "duration_minutes": 45, "required_providers": 1,
  "slots": [{ "time": "10:30", "end_time": "11:15", "next_day": false, "available": 2, "provider_ids": ["…"] }],
  "reason": null, "reason_params": null }
```

No times? Then `reason` says why (e.g. `same_day_closed`, `online_booking_hours` with `reason_params.from/until`, or `not_enough_staff` with `reason_params.n` when the team is too small for a duo treatment). If `reason` is `null` and there are no slots, the day is fully booked.

- Duo treatment (`required_providers` ≥ 2): `available` = how many such appointments still fit at that moment; a chosen `provider_id` is the lead staff member.
- If the venue hides the number of free places, `available` is always `1` and `provider_ids` is empty. Then don't show "X left".

## Restaurant variant

1. **Party size**: between `venue.booking.min_party_size` and `max_party_size`.
2. **Day**: `GET /calendar` as above (without `provider_id`).
3. **Time**: `GET /availability?date=2026-12-04&party_size=4`. `available` = free places.

For a restaurant, never send `provider_id` (that returns `422 invalid_input`).

## 5. Hold the time

As soon as the guest picks a time:

```js
const hold = await api('/holds', { method: 'POST', body: {
  date: '2026-12-04', time: '10:30', party_size: 1,
  service_ids: [serviceId], variant_ids: [variantId], pending_ids: [],
  provider_id: providerId,           // omit or null = no preference
  session_id: sessionId,             // one random ID per visitor/tab
}});
```

- `session_id`: create one per visitor with `crypto.randomUUID()` and store it in `sessionStorage` at most. A new hold from the same session replaces the previous one.
- The server checks the time again against all rules (opening hours, blocks, holidays, capacity, service rules). If it is gone: `409 slot_unavailable` → fetch the times again.
- Response: `hold_id`, `expires_at`, `capacity_reserved`, `end_time`, `duration_minutes`, `provider_id`, `extra_provider_ids` (for a duo treatment the extra staff members, otherwise empty) and `deposit: { required, amount_cents, currency }`.
- A duo treatment always gets a real hold (`capacity_reserved: true`), even at a venue that otherwise works without holds.

**`capacity_reserved`**

- `true`: the time is really held for you until `expires_at`. Show a countdown ("Your time stays reserved for 4:59").
- `false`: the venue works without holds (or with table management). The time was free at the check, but is not held; `hold_id` then starts with `nh_`. The flow stays the same, only the text next to the countdown changes ("Complete your booking within 5 minutes").

If the guest goes back or closes the flow, release the time: `DELETE /holds/{hold_id}`. After `expires_at` you request a new hold.

## 6. Guest details

Ask for first name, last name, email, optionally phone and notes.

- Phone is required if `venue.booking.phone_required` is `"always"`, or `"conditional"` and the party size ≥ `phone_required_min_party_size`.
- Next to the booking button, always show the **privacy and terms notice** with links to `venue.privacy_url` and `venue.terms_url`, for example: "By booking you agree to the terms and the privacy policy of {venue}."
- Don't store guest details in `localStorage` or cookies.

**Booking for a company (optional).** If the guest wants an invoice made out to a company, send a `company` block: `name` (required), `vat_number` (VAT number with country prefix; spaces and dots are fine) and `reference` (purchase order or reference). A VAT number in the wrong format gives `400 invalid_input` on `company.vat_number`. Whether the number really exists is checked by Callyndar against EU VIES after the booking; if VIES is unreachable, the booking still goes through. Leave the block out for a private booking.

Does a deposit have to be paid (`hold.deposit.required`)? Then read [Deposits](/developers/en/deposits) first.

## 7. Book

```js
const res = await fetch(`${API}/bookings`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': crypto.randomUUID(),   // new per booking attempt
  },
  body: JSON.stringify({
    hold_id: hold.hold_id,
    guest: { first_name: 'An', last_name: 'Peeters', email: 'an@example.com', phone: '+32 470 12 34 56' },
    notes: 'A seat by the window, please',
    locale: 'nl',
    // company: { name: 'TEST Studio BV', vat_number: 'BE0123456749', reference: 'PO-118' },   optional
    turnstile_token: turnstileToken,
    // payment_intent_id: 'pi_…'   only after a deposit
  }),
});
```

The services, variants and staff member come from the hold; you don't send them again.

Response (`201`):

```json
{ "booking": { "id": "…", "status": "confirmed", "date": "2026-12-04", "time": "10:30", "end_time": "11:15",
  "party_size": 1, "provider_id": "…", "extra_provider_ids": [],
  "services": [{ "id": "…", "name": "Women's haircut", "variant_id": null, "variant_name": null, "duration_minutes": 45, "price_cents": 3500 }],
  "deposit_paid": false, "manage_url": "https://www.callyndar.com/r/…" } }
```

| `status` | What you show |
|---|---|
| `confirmed` | "Your booking is confirmed. You will receive an email." |
| `pending` | "Your request has been received. The venue will confirm it as soon as possible." |
| `waitlisted` | "It is fully booked; you are on the waitlist. The venue will contact you." |

Show the `manage_url`: the guest can cancel or reschedule there (the same link is in their confirmation email). Cancelling or rescheduling through the API is not possible.

## When things go wrong

- `409 slot_unavailable` or `409 hold_expired`: fetch `GET /availability` again and let the guest choose another time.
- `403 turnstile_failed`: `turnstile.reset()` and try again.
- `409 deposit_required`: start the deposit.
- `429 rate_limited`: wait `Retry-After` seconds.

All codes are in [Errors and limits](/developers/en/errors-and-limits).
