# SimplyBook.me API troubleshooting for AI agents

Companion to [setup.md](setup.md). Sections follow the setup steps. Each entry: what you see → why → what to do.

When reporting a problem to the user or on the developer forum (https://tech-support.simplybook.me/), include the exact request (method, URL, headers without secret values, body) and the full response body. Never include tokens, keys or passwords.

## First check: which API are you calling?

Many problems come from mixing the two APIs.

| | REST API (current) | JSON-RPC API (legacy) |
|---|---|---|
| Host | `https://user-api-v2.<domain>` | `https://user-api.<domain>` |
| Request | `GET`/`POST`/`PUT`/`DELETE` to paths like `/admin/bookings` | `POST` of `{"jsonrpc":"2.0","method":"...","params":[...],"id":1}` |
| Auth headers | `X-Company-Login` + `X-Token` | `X-Company-Login` + `X-Token` (public) or `X-User-Token` (admin) |
| Errors | HTTP status + `{"code","message","data"}` | HTTP 200 + `{"error":{"code":-32xxx,"message":...}}` |
| Reference | OpenAPI: `https://simplybook.me/api/swagger-admin`, `https://simplybook.me/api/swagger-public` | [json-rpc.md](json-rpc.md) |

If you get a list of methods (SMD) instead of data, "Method not found", or negative codes like `-32600`/`-32601` inside `{"error": {...}}` with HTTP 200, you are talking to JSON-RPC — see [json-rpc.md](json-rpc.md).

## Step A1–A2: credentials

**`401` on `POST /public/auth/token`**
- The `key` is not the **public REST API key**. Copy "Your public REST API key" from **Custom Features → API** settings. The JSON-RPC API key, secret key, API User Keys and the public MCP key do not work here.
- The **API** custom feature is disabled — enable it (Smart Widget also enables it).
- Keys were regenerated ("Generate new keys" rotates all of them) — copy the new one.

**Where is the API User Key page?** Linked from the **API** custom feature settings; the address ends with `/v2/r/#/api-keys`. Only administrators can create keys. A key is tied to the staff user who created it: log in with that user's login.

**Warning before creating the first API User Key on a live account:** it also turns on email IP verification for *password* logins of that company, and it stays on even if the key is deleted. Existing integrations that log in with a staff password from a new IP will start receiving `require2fa` responses. Tell the user before they create the key, and move such integrations to API User Keys.

## Step A3: getting a token

**`Invalid company` / `403` "company not found"**
- Wrong regional host. Use the **REST API Endpoint** shown in **Custom Features → API** (`.it`, `.asia`, `.us` and enterprise domains exist). This also applies to `/admin/auth/refresh-token`.
- Wrong company login (it is the account name from `<login>.simplybook.me`, not the business name or email).

**`require2fa: true` and an empty `token`**
- You logged in with a staff password; the company uses Google Authenticator, HIPAA (SMS) or email IP verification. For automation, use an **API User Key** as the password — it skips 2FA and IP verification.
- For an interactive tool with a real person: send the code with `POST /admin/auth/2fa` `{company, session_id: <auth_session_id>, code, type}` where `type` is one of `allowed2fa_providers` (`ga`, `sms`, `email`). Both calls must come from the same IP. Wrong code → `400` `data.code: ["Invalid code"]`; expired session → `403 Session expired`.

**`403 Too many attempts please try later.`**
- The limit is per IP across all processes and also counts token refreshes; it can trigger after a few logins in a short time and usually clears within a few minutes. Stop logging in on every request: cache the token for its lifetime (about 1 hour), share it between processes, log in again only after a `401`, and back off on this error.

**`401` with `"code": 401, "message": "Unauthorized"` or `"code": 419, "message": "Token Expired"`**
- The token is invalid or expired (about 1 hour; shorter for HIPAA companies), the user's password changed, the user was blocked, or the API User Key was revoked. Get a new token. For admin, try `POST /admin/auth/refresh-token` `{company, refresh_token}` first.

**`401` on refresh**
- A refresh token works **once**. Store the new `refresh_token` from each refresh. Do not refresh the same token from several workers — use one shared token store with a lock. HIPAA companies with a session limit get no refresh token; log in again.

**`401`/`403` on every call although login worked**
- Headers: send `X-Company-Login` and `X-Token`. `Authorization: Bearer`, `X-API-KEY`, a `token` query/body parameter are ignored.
- A public token was sent to `/admin/...` (or the other way round). Each surface has its own token.
- A token of company A was used with `X-Company-Login` of company B → `403`.
- No-code tools (n8n, Make, Zapier): check that the header contains the token value and not the literal expression text.

**`403` on `GET /public/booking` or on client memberships**
- These endpoints need a logged-in **client** token: `POST /public/clients/login` (requires the Client login custom feature). Note the path is `/public/booking`, not `/public/bookings`.
- `GET /public/booking` lists only confirmed bookings by default; add `filter[confirmed_only]=0` to see bookings waiting for approval and cancelled bookings (check `status`).

**CORS errors in the browser**
- The REST API allows cross-origin calls with these headers. A CORS error usually means a wrong URL (404/500 page without CORS headers) — check the URL and host first. Admin calls should not come from the browser at all.

## Step A5: booking flow

**Slots are empty**
- Normal when the combination has no availability. The API returns exactly what the public booking page shows — compare with the booking page for the same service, provider and date.
- The provider is not linked to the service, or the service and provider schedules do not overlap (day off, special days, breaks). Check `GET /public/providers?filter[service_id]=<id>`, then try without `provider_id` (any provider).
- `400 Too long period`: request at most 45 days per call. The limit applies to the slots request only; booking further ahead is allowed up to the company's "max time till event".
- `first-available-day` is only a hint and can return a day without free slots — always confirm with `/timeline/slots`.
- `curl` with `filter[...]` in the URL and no `-g` fails silently with `-s` (`bad range in URL`) — use `curl -g`.
- Booking restrictions: minimum time before booking, maximum days ahead, calendar-sync busy events, location filter.
- Empty slots are never a rate-limit signal; rate limiting returns `429`.

**`400` on `POST /public/booking/item` or `POST /admin/bookings`**
- Read `data` in the response: it maps each field to its error; `message` is often empty. Log the whole body.
- `Captcha verification required` → the company uses captcha for API bookings. Get a challenge from `GET /public/captcha/challenge`, load `captcha-widget.js` from `widgetUrl`, let the end user solve the `SBCaptcha` widget and send `captcha_token` (snippets: **Anti-Fraud/Spam Protection** settings → **Integration guide**). Without a client-facing UI, ask the user to turn off **Enable captcha for API integrations** in **Anti-Fraud/Spam Protection**, or book through the admin API. Do not try to bypass it.
- `Client authorization required` → the **Client login** feature is on: log the client in (`POST /public/clients/login`) and book with the client token, without `client` in the body.
- `data.terms.user_terms: Value is required` → send `"terms": {"user_terms": true}` (and the other terms listed as enabled in `GET /public/clients/terms`) once the client has accepted them.
- `data.client_membership_id: Membership is required` → the service is sold through memberships: pass the client's `client_membership_id`, or (admin API, only if the business agrees) `skip_membership: true`.
- `start_datetime` must be `YYYY-MM-DD HH:MM:SS` in the **company timezone** and must be one of the returned slots. Do not send UTC or ISO strings with `T`/`Z`/offsets.
- Intake form values: `additional_fields` is a list `[{"field": "<name>", "value": ...}]` where `name` is the hash-like key from `GET /public/additional-fields?filter[service_id][]=<id>` — not `field_name` (the label) and not a numeric id. Required fields must be present.
- Admin bookings need an existing `client_id` — find the client first (`GET /admin/clients?filter[search]=<email>`, then compare the email exactly), create it only if missing.
- Memberships, packages, payment or approval rules can reject a booking ("Membership is required"); check which custom features the service uses.

**`400` on `POST /admin/clients`: `phone: Value is required and can't be empty`**
- The phone is required for this company. Check `GET /admin/clients/fields` for required fields. Custom client fields are saved separately with `/admin/clients/field-values`.

**Duplicate clients**
- Public bookings with `client: {name, email, phone}` create a new client unless the business uses **Client login**. To reuse clients, look them up and book through the admin API with `client_id`, or log the client in on the public API.

**Times are off by some hours**
- The API uses the company timezone without an offset (`GET /public/config` → `timezone`). Convert to and from the user's timezone in your code.

**Paid services**
- A booking for a service with online payment is pending until the invoice is paid; it does not trigger `new_booking` webhooks until then, and unpaid bookings may be cancelled automatically by the payment timeout. Check the invoice/payment endpoints in the spec. When importing historical bookings, ask the user to disable payment features during the import.

## Step A6: webhooks

**Webhook does not arrive**
- Your endpoint must be public HTTPS (no localhost, no basic auth in the URL, valid certificate chain), answer `2xx` within 5 seconds, and not redirect.
- Booking events fire only for **confirmed** bookings (see Paid services above). Bookings needing approval fire when approved.
- Debug: point a subscription at a request-inspection service, create a booking from the admin panel, compare payloads.
- Failed deliveries are retried after 10 min, 30 min, 1 h, 3 h, 12 h, 24 h (number of retries is set in the API settings).
- Do not subscribe the same URL both through the legacy **Callback URL** (API custom feature settings) and `/admin/webhooks` — you will get duplicates.
- Each event allows at most 5 active subscriptions; creating a 6th silently deactivates the oldest one (it is not deleted).

**Signature check fails**
- `X-Signature` is HMAC-SHA256 of the **raw request body** with the company **secret key** (from the API settings). Compute it on the bytes you received, before parsing or re-serialising JSON.

**Payload has only IDs**
- By design. Booking payloads carry `booking_id`, `booking_hash`, `company`, `notification_type` (`create`, `change`, `cancel`). Fetch details with `GET /admin/bookings/{id}`.

## Limits and errors

**`429 API calls limit exhausted` / `429 Too many requests`**
- Plan for about 5,000 requests per day per company, at most 2 parallel requests and 5 per second. Cache reference data (services, providers, fields) and the token, use webhooks instead of polling, request slots for a date range instead of one call per day/provider, and back off before retrying.

**`402 Your subscription has expired`**
- The company's plan has expired; the user must renew it.

**`500` / `502` / `503`**
- Retry with exponential backoff. If it persists, report the request and response (without secrets) to the forum.

**Response has new fields / types changed**
- Parse tolerantly: ignore unknown fields. Re-download the OpenAPI spec when something looks different.

## Scenarios B and C: MCP

**The MCP server does not appear / `401` on connect**
- The **MCP** custom feature (Beta) is not enabled, or the URL was typed by hand. Copy the connector URL from the MCP feature settings.
- Admin MCP uses OAuth discovery: the client must support remote HTTP MCP servers with OAuth. Complete the browser sign-in as the staff user whose permissions the assistant should get.
- Public MCP needs the header `Authorization: Bearer <public MCP key>` (not the public REST API key) and no OAuth.

**Access stopped working**
- Admin MCP access ends when the user revokes it in the MCP settings, changes the password, or the feature is disabled. Reconnect.
- The public MCP key was regenerated — update the agent configuration.

**The assistant does not know how to use the tools well**
- Download the instructions (skill) from the MCP feature settings and install them in the assistant.
