# Getting started

Create a key, set up domains, protect your form against bots and make your first call.

## 1. Create a key

A key belongs to exactly one venue. The key determines the venue: a venue ID never appears in the URL.

1. Sign in as the venue owner, or as a team member or partner with write access to the **Integrations** (*Integraties*) page.
2. Go to `/integrations` → the **API & own website** (*API & eigen website*) card → **Create key** (*Sleutel aanmaken*).
3. Copy the key `cal_pk_live_…`. You can copy it again later.

The API works from the **Starter** plan. On a free plan, or for a stopped or inactive venue, every call returns `403 not_enabled`. Exception: venues that run through a partner (reseller) keep using the API on the free plan too, within that plan's monthly limit (20 bookings). Once that limit is reached, `POST /bookings` returns `403 not_enabled` with `details.reason = "booking_limit"`. A venue that a partner is still setting up as a draft already answers read calls but not yet holds and bookings (`details.reason = "venue_in_setup"`, see [Testing](/developers/en/testing#during-the-setup-phase)).

There is one active key per venue. With **Rotate** (*Roteren*) you get a new key and the old one keeps working for another 24 hours (or you revoke it right away), so you can update the site without pressure.

## 2. Allowed domains

On the key you set the domains the site runs on, exactly as the browser sends them as `Origin`:

| Input | Meaning |
|---|---|
| `https://www.salon-voorbeeld.be` | exactly this domain |
| `https://salon-voorbeeld.be` | the domain without `www` (add it separately) |
| `https://*.salon-voorbeeld.be` | any subdomain, but not `salon-voorbeeld.be` itself |

- `https://` only. No paths (`/boeken`), no `http://`.
- **Allow localhost** (*Localhost toestaan*, on/off on the key) permits `http://localhost:*` and `http://127.0.0.1:*` while you build. Turn it off as soon as the site is live.
- If a call comes from the browser of another domain, the API responds with `403 forbidden_origin` without CORS headers. The browser then shows a CORS error in the console.

## 3. Bot protection

**Protecting your form against bots is your job as the site builder.** Put your own captcha or your own Cloudflare Turnstile on the booking form, as you would on any form on your site. On top of that, the API already checks domains, limits per key and per visitor, and all booking rules (see [Security](/developers/en/security)).

**Optional: Callyndar's Turnstile per key.** The owner can turn on **Bot check (Turnstile)** (*Botcontrole (Turnstile)*) on the key; it is off by default. When it is on, booking (`POST /bookings`) and starting a deposit (`POST /holds/{id}/deposit`) require a Turnstile token from Callyndar's widget. `GET /venue` tells you whether that is the case with `turnstile_required`, and gives you the `turnstile_site_key` you then have to use:

```html
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit" async defer></script>
<div id="turnstile"></div>
```

```js
const widgetId = turnstile.render('#turnstile', {
  sitekey: venue.turnstile_site_key,
  callback: (token) => { turnstileToken = token; },
});
// after a failed attempt: turnstile.reset(widgetId)
```

A token can be used once. After a `turnstile_failed` error, call `turnstile.reset()` and send the new token.

If you use this option, Callyndar has to add every domain of your site to its Turnstile widget. Pass the domain on to Callyndar. If `turnstile_required` is `false`, simply omit `turnstile_token`.

## 4. Your first call

Always send the key in the `Authorization: Bearer …` header. A key in the URL (`?key=`) does not work: it would end up in logs.

```js
const API = 'https://www.callyndar.com/api/v1';
const KEY = 'cal_pk_live_YOUR_KEY';

const res = await fetch(`${API}/venue`, { headers: { Authorization: `Bearer ${KEY}` } });
if (!res.ok) {
  const { error } = await res.json();
  throw new Error(`${error.code}: ${error.message}`);
}
const { venue } = await res.json();
console.log(venue.name, venue.timezone, venue.booking_mode);
```

What you get back:

- `booking_mode`: `"services"` (salon, barber, clinic: services → staff member → time) or `"party_size"` (restaurant: party size → time).
- `timezone`: all dates (`YYYY-MM-DD`) and times (`HH:MM`) in the API are the **venue's local time**.
- `privacy_url` and `terms_url`: must be shown next to the booking button.
- `booking`: the venue's rules (min/max party size, days ahead, whether a phone number is required, whether deposits are enabled).

## Next step

Read [The booking flow](/developers/en/booking-flow), or open the example [`boeking.html`](/developers/voorbeeld/boeking.html) and fill in your key.
