5 min read

# Build an app with OAuth

**Build an app that Bookingmood users connect with one click. Your users choose** _**Connect to Bookingmood**_ **in your app, sign in to Bookingmood and pick the organizations your app may access. Your app then calls the** **[REST API](https://www.bookingmood.com/en-US/api-reference)** **and receives** **[webhooks](https://www.bookingmood.com/en-US/docs/developers/webhooks)** **on their behalf, without anyone copying an API key.**

This guide walks through an app that keeps a copy of each organization's bookings: connecting, the first sync, staying in sync with webhooks, and handling disconnects. For a script that works with one organization of your own, an [API key](https://www.bookingmood.com/en-US/docs/developers#api-keys) is simpler.

## [1. Get a client ID and secret](#1-get-a-client-id-and-secret)

[Contact us](https://www.bookingmood.com/en-US/contact) with:

- The name of your app, as users should see it when they connect.
- Your logo and the URL of your website.
- Your redirect URIs: the URLs in your app that Bookingmood sends users back to after they connect, such as `https://app.example.com/bookingmood/callback`. They have to use HTTPS. Add one per environment, for example production and staging.

You get a `client_id` and a `client_secret`. The secret is shown once, so store it on your server. If it leaks, ask us for a new one: the old one stops working right away.

Apps that run on the user's device, such as desktop apps and AI assistants, can't keep a secret. They register themselves instead, see [Authentication](https://www.bookingmood.com/en-US/api-reference/authentication#oauth).

## [2. Choose your scopes](#2-choose-your-scopes)

Ask for the least your app needs. The user sees each area on the consent screen and can lower write access to read access, or leave areas out.

| Your app | Scopes |
| --- | --- |
| Copies bookings | `bookings:read webhooks:write offline_access` |
| Also changes bookings | `bookings:write webhooks:write offline_access` |
| Also reads units and prices | add `products:read` |

`offline_access` gives a refresh token, so your app keeps access without asking the user again. A webhook can only subscribe to events of data your app may read: `bookings.created` needs `bookings:read`, `members.created` needs `organization:read`. The [API reference](https://www.bookingmood.com/en-US/api-reference) shows the scope of each request.

## [3. Send the user to Bookingmood](#3-send-the-user-to-bookingmood)

When the user chooses _Connect to Bookingmood_, redirect them to:

```
https://www.bookingmood.com/oauth/authorize
  ?response_type=code
  &client_id=YOUR_CLIENT_ID
  &redirect_uri=https%3A%2F%2Fapp.example.com%2Fbookingmood%2Fcallback
  &scope=bookings%3Aread%20webhooks%3Awrite%20offline_access
  &state=RANDOM_STATE
  &code_challenge=CODE_CHALLENGE
  &code_challenge_method=S256
```

- `state` is a random value you store in the user's session and check when they come back.
- `code_challenge` is PKCE, which every client uses, also those with a secret. Generate a random `code_verifier` of 43 to 128 characters, store it with the `state`, and send the base64url-encoded SHA-256 hash of it as the challenge. Most OAuth libraries do this for you.

The user signs in to Bookingmood, picks the organizations your app may access and approves. They can only pick organizations they're an admin of. Bookingmood then redirects to your redirect URI with `code` and `state`, or with `error=access_denied` when the user declined.

A user who already connected your app with these scopes skips the consent screen. Add `prompt=consent` to show it anyway, for example to let them add an organization.

## [4. Exchange the code for tokens](#4-exchange-the-code-for-tokens)

From your server, within 5 minutes:

```
curl https://www.bookingmood.com/oauth/token \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -d grant_type=authorization_code \
  -d code=THE_CODE \
  -d code_verifier=THE_CODE_VERIFIER \
  -d redirect_uri=https://app.example.com/bookingmood/callback
```

You can also send `client_id` and `client_secret` in the body instead of with HTTP Basic authentication. The response:

```
{
  "access_token": "bmo_at_…",
  "expires_in": 3600,
  "organizations": [
    { "id": "6f1c…", "name": "Villa Rosa" }
  ],
  "refresh_token": "bmo_rt_…",
  "scope": "bookings:read webhooks:write offline_access",
  "token_type": "Bearer"
}
```

`organizations` lists the organizations the tokens reach. Store their ids with the user's account in your app.

## [5. Call the API](#5-call-the-api)

Send the access token as a bearer token:

```
curl "https://www.bookingmood.com/api/v1/bookings?organization_id=eq.6f1c…" \
  -H "Authorization: Bearer bmo_at_…"
```

A token covers every organization the user connected, so a read returns rows of all of them. Filter on one with `organization_id=eq.…`, and set `organization_id` in the body when you create a row.

Changes your app makes show in the organization's activity log as your app, on behalf of the user who connected it.

## [6. Refresh the access token](#6-refresh-the-access-token)

Access tokens last an hour. Before one expires, or when a request gets `401`, get a new one:

```
curl https://www.bookingmood.com/oauth/token \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -d grant_type=refresh_token \
  -d refresh_token=bmo_rt_…
```

The response has a new access token, a new refresh token and the current `organizations`. Replace both tokens in your database.

- A refresh token works once. If two of your workers refresh at the same time, the second one still gets tokens when it comes within 30 seconds of the first. Using a refresh token again after that disconnects your app, since it looks like the token leaked. Refresh in one place, or lock per connection, and keep the newest token.
- A refresh token expires 30 days after it was issued. Each refresh gives a new one, so a connection your app uses at least once a month stays connected.

## [7. Copy the existing bookings](#7-copy-the-existing-bookings)

Read each organization's bookings page by page. A request returns at most 1000 rows; see [Sorting and pagination](https://www.bookingmood.com/en-US/api-reference/sorting-pagination).

```
curl "https://www.bookingmood.com/api/v1/calendar_events?organization_id=eq.6f1c…&select=*,booking:bookings(*)&order=updated_at,id&limit=1000&offset=0" \
  -H "Authorization: Bearer bmo_at_…"
```

The stays of a booking are its calendar events: one per unit, with the dates and the status. The booking holds the guest details and the totals. See [Bookings through the API](https://www.bookingmood.com/en-US/docs/developers/booking-api).

Each connection may make 120 requests per minute. The response headers show what's left, and a `429` response has a `Retry-After` header.

## [8. Stay in sync with webhooks](#8-stay-in-sync-with-webhooks)

Register a webhook in each organization, right after the user connects:

```
curl "https://www.bookingmood.com/api/v1/webhooks" \
  -H "Authorization: Bearer bmo_at_…" \
  -H "Content-Type: application/json" \
  -d '{
    "organization_id": "6f1c…",
    "endpoint": "https://app.example.com/bookingmood/webhooks",
    "events": ["bookings.created", "bookings.updated", "calendar_events.created", "calendar_events.updated"],
    "description": "Sync with Example",
    "source": "example"
  }'
```

Store the webhook's `id` and `signing_secret` from the response, and [verify the signature](https://www.bookingmood.com/en-US/docs/developers/webhooks#verify-events-are-sent-from-bookingmood) of every event. Each event holds the new and old version of the row, with its `organization_id`, so you know which connection it belongs to.

Events can arrive more than once, and out of order. Compare `updated_at` with your copy, or fetch the row again, before you overwrite it. To catch anything a failed delivery missed, also read the rows changed since your last sync now and then, with `updated_at=gt.…`.

## [9. Handle disconnects](#9-handle-disconnects)

Your app loses access to an organization when:

- The user disconnects your app under _Connected apps_ in their profile menu.
- An admin of the organization removes your app under _[Settings](https://www.bookingmood.com/admin/organizations/-/settings/api-keys)_ › _[API keys](https://www.bookingmood.com/admin/organizations/-/settings/api-keys)_.
- The user who connected your app leaves the organization or is no longer an admin there.

The webhooks your app created there are then disabled, and the organization drops out of the `organizations` of the next token response. Reads no longer return its rows. When it was the last organization of the connection, or the user disconnects your app altogether, the connection ends: requests get `401` and a refresh gets `invalid_grant`. In each case, show the user that the connection was lost and offer to connect again.

When a user connects your app to the organization again, its disabled webhooks there are enabled again, as long as the new scopes cover their events. Another admin can connect it too, for example after the first one left.

To disconnect from your side, for example when the user deletes their account in your app, revoke the refresh token:

```
curl https://www.bookingmood.com/oauth/revoke \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -d token=bmo_rt_…
```

This removes your app's access to every organization of that connection and disables its webhooks.

## [Endpoints](#endpoints)

|  | URL |
| --- | --- |
| Authorization | `https://www.bookingmood.com/oauth/authorize` |
| Token | `https://www.bookingmood.com/oauth/token` |
| Revocation | `https://www.bookingmood.com/oauth/revoke` |
| Metadata | `https://www.bookingmood.com/.well-known/oauth-authorization-server` |
| API | `https://www.bookingmood.com/api/v1` |

Last modified November 26, 2026
