# Introduction

With the Bookingmood API you can access and manage your data in a programmatic way, using HTTP requests. The structure of the Bookingmood API is based on [PostgREST v14](https://docs.postgrest.org/en/v14/index.html).

## [Base URL](#base-url)

All endpoints are relative to `https://api.bookingmood.com/v1`. Every request must be [authenticated](https://www.bookingmood.com/el-GR/api-reference/authentication) with an API key, which scopes all data to its organization.

## [OpenAPI spec](#openapi-spec)

The whole API, including the booking flow, is described in an [OpenAPI 3.0 spec](https://api.bookingmood.com/v1/openapi.json) with request and response schemas. Import it into tools like Postman or Insomnia, or use it to generate a typed client.

## [Requests](#requests)

Each [core resource](https://www.bookingmood.com/el-GR/api-reference/products) supports some or all of the following methods:

- `GET /{resource}` lists records. Use [selecting](https://www.bookingmood.com/el-GR/api-reference/selecting), [filtering](https://www.bookingmood.com/el-GR/api-reference/filtering) and [sorting & pagination](https://www.bookingmood.com/el-GR/api-reference/sorting-pagination) to shape the result.
- `POST /{resource}` creates one record, or several when the body is an array.
- `PATCH /{resource}` updates all records matching the filters.
- `DELETE /{resource}` deletes all records matching the filters.

Request bodies are JSON, sent with the `Content-Type: application/json` header. Updates and deletes without filters apply to every record you have access to, so always filter, for example on `id=eq.{id}`.

When you change the status or unit of [calendar events](https://www.bookingmood.com/el-GR/api-reference/calendar_events), or delete them, Bookingmood plans the booking's scheduled messages and tasks again, within a couple of minutes. Guests aren't emailed about a new status unless you send the header `X-Notify-Guests: true`. Then the guest gets the unit's "Booking confirmed", "Booking cancelled" or "Booking changed to pending" message, as when you change the status in Bookingmood.

## [Responses](#responses)

Responses are JSON. By default the API sends `Prefer: count=exact, return=representation` to PostgREST, so:

- Creates, updates and deletes return the affected records.
- List responses include a `Content-Range` header with the returned range and the total number of matching records, for example `0-9/42`.

To change this, send your own `Prefer` header. For example, `Prefer: return=minimal` returns `204 No Content` for updates and deletes.

## [Errors](#errors)

The API uses conventional HTTP status codes:

- `400` The request is malformed, for example an unknown column, an invalid filter, or a body that doesn't match the endpoint's schema.
- `401` The API key is missing or invalid.
- `403` The API key has no permission for this record.
- `405` The resource does not exist, or the method is not available for it.
- `409` The request conflicts with existing data, for example a duplicate key.
- `429` The API key made more requests than its rate limit allows.
- `5xx` Something went wrong on our side.

Errors have a JSON body following [the PostgREST error format](https://docs.postgrest.org/en/v14/references/errors.html), with a `code`, `message`, `details` and `hint`. When a request doesn't match an endpoint's schema, for example on the booking flow endpoints, the code is `BM400` and `details` lists each invalid field. Every request, including failed ones, is logged and can be inspected through the [API requests](https://www.bookingmood.com/el-GR/api-reference/api_requests) resource.

## [Rate limits](#rate-limits)

Each API key may make 120 requests per minute, counted over a sliding window of the last 60 seconds. Every response says where the key stands:

- `RateLimit-Policy` The limit and window, for example `"default";q=120;w=60`.
- `RateLimit` The requests remaining and the seconds until more become available, for example `"default";r=87;t=23`.
- `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset` The same values, for clients that read these headers.

Requests over the limit get a `429 Too Many Requests` response with a `Retry-After` header: wait that many seconds before retrying, and back off further on repeated 429s rather than retrying in a tight loop. Rejected requests don't count towards the limit, and show up in the key's usage and in [API requests](https://www.bookingmood.com/el-GR/api-reference/api_requests) with status `429`.

To stay well within the limit, paginate large lists instead of fetching everything at once, embed related resources instead of fetching them one by one, use [webhooks](https://www.bookingmood.com/el-GR/api-reference/webhooks) instead of polling, and spread scheduled syncs out rather than starting them all at once. The settings of each API key show its limit and current usage. If your integration needs more, request a higher limit from there.

Example response headers

HTTP

```
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Range: 0-9/42
```

Example error

JSON

```
{
  "code": "PGRST204",
  "details": null,
  "hint": null,
  "message": "Could not find the 'nme' column of 'products' in the schema cache"
}
```
