# Take appointments from your own website or app

> Show free times on your own website or app, book the appointment through the API, move or cancel it, block time and run a waitlist, while Book-and-Pay sends the WhatsApp confirmation and reminders for you.

In this guide your own website or app takes appointments through app2email's Book-and-Pay and Calendar API. Your page shows the services and the free times, the customer picks one, and your server books it with one call.

**What the customer sees:** they pick a haircut at 9:00 on your website and type their name and WhatsApp number. A few seconds later a WhatsApp message from your business arrives: "You're booked: Haircut on ... at 9:00 AM (30 min). Reference BK-7Q3M2A. Reply CANCEL if your plans change.", with a calendar file to add it to their phone. Before the visit a reminder arrives with Confirm, Reschedule and Cancel buttons.

**What you see:** the appointment in your connected calendar (Google, Microsoft 365, Apple iCloud, or app2email's own calendar app), an email for each new booking, and webhook events for every booking, move, cancellation and waitlist offer, wherever the booking was made.

You do not send any of the WhatsApp messages yourself. Book-and-Pay writes the confirmation, the reminders, the "moved" and "cancelled" notices, and picks an approved template when the customer's 24 hour window is closed.

## How it works

1. Your server reads the services (`GET /bookings/services`) and the free times (`GET /bookings/availability` or `GET /bookings/next`).
2. When the customer picks a time, your server can hold it for a few minutes (`POST /bookings/holds`) while they type their details.
3. Your server books it (`POST /bookings`). Book-and-Pay writes the calendar event, sends the WhatsApp confirmation, emails you, and sends `booking.created` to your webhook.
4. Later you move it (`POST /bookings/{id}/reschedule`), change its details (`PATCH /bookings/{id}`), or cancel it (`POST /bookings/{id}/cancel`). The customer is told on WhatsApp each time.
5. You block time off (`POST /calendar/blocks`) and put customers on the waitlist of a full day (`POST /bookings/waitlist`). When a time opens, Book-and-Pay offers it to them on WhatsApp.

Every call goes to `https://api.app2email.com/v1/YOUR_NUMBER` with `Authorization: Bearer YOUR_API_KEY`. `YOUR_NUMBER` is your WhatsApp number: country code first, digits only.

## What you need

- **Book-and-Pay set up first.** The services, opening hours, calendar and message texts come from the dashboard's **Book-and-Pay** page (https://www.app2email.com/dashboard/app/book). Set it up and switch it on there: see [Appointment booking on WhatsApp](/guides/booking). Switching it on also creates the utility templates Book-and-Pay uses outside the 24 hour window (Meta reviews them, usually within the hour). Without Book-and-Pay the booking calls answer 403 `booking_not_enabled`.
- **A WhatsApp number connected to app2email**, on a paid plan and live. Without a plan calls answer 403 `plan_not_allowed`; a paused service answers 403 `service_not_live`. See [Getting started](https://www.app2email.com/docs/onboarding).
- **An API key** from [the API key page](https://www.app2email.com/dashboard/apikey) with these scopes:

| Scope | Why you need it |
| --- | --- |
| `bookings:manage` | Book, hold, move, change and cancel appointments, block time, the waitlist. It also covers every booking read |
| `messages:read` | Enough on its own for a key that only reads: services, free times, appointments, the calendar, the waitlist |
| `webhooks:manage` | Register the webhook once (`POST /webhooks`). You can also add it on the API key page under Webhooks, without code |

The Default key (made before keys had permissions) does not have `bookings:manage`. Create a key with that scope, or with Full access (`*`). `GET /v1/YOUR_NUMBER/me` shows the scopes of the key you have.

- **A server of your own.** The key stays on your server: never put it in a web page or a mobile app. Your page asks your server for the free times and sends the booking to your server, and your server calls app2email.

<Tip>
**Trying it out.** The instant sandbox (the demo number `12025550100`) has no booking calls: they answer 403 `not_in_instant_sandbox`. A **sandbox key** on your own number (a key with the sandbox flag, made on the API key page) reads your real services, free times, appointments, calendar and waitlist, so you can build the whole "pick a time" part with it. Every call that changes something (book, hold, move, cancel, block, waitlist) answers 403 `sandbox_key` with it. To try a real booking, use a normal key and your own phone number as the customer, then cancel the appointment again. Details: [Sandbox](/api/sandbox).
</Tip>

## Book an appointment in four steps

<Steps>
  <Step title="List the services">
    `GET /bookings/services` (scope `bookings:manage` or `messages:read`) gives the services a customer can book, with their length, price, description and the staff members who do each one. The `id` goes into every other call.

    <CodeGroup>

    ```bash cURL
    curl https://api.app2email.com/v1/YOUR_NUMBER/bookings/services \
      -H "Authorization: Bearer YOUR_API_KEY"
    ```

    ```javascript Node.js
    const API = `https://api.app2email.com/v1/${process.env.NUMBER}`;
    const headers = { Authorization: `Bearer ${process.env.API_KEY}` };

    const res = await fetch(`${API}/bookings/services`, { headers });
    const { services, timezone } = await res.json();
    console.log(timezone, services);
    ```

    ```python Python
    import os, requests

    API = f"https://api.app2email.com/v1/{os.environ['NUMBER']}"
    HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}"}

    res = requests.get(f"{API}/bookings/services", headers=HEADERS, timeout=10)
    print(res.json())
    ```

    </CodeGroup>

    **What you get back:**

    ```json
    {
      "success": true,
      "request_id": "c6sv7",
      "services": [
        { "id": "haircut", "name": "Haircut", "duration_min": 30, "price": "$40", "description": null, "staff": ["maria", "tom"] }
      ],
      "timezone": "Australia/Sydney",
      "enabled": true
    }
    ```

    `staff` is empty when the business has no staff. `GET /bookings/staff` lists the staff members (`provider_id` in the other calls) with the services each one does. `enabled` must be `true`: Book-and-Pay is switched on.
  </Step>
  <Step title="Find the free times">
    `GET /bookings/availability` (scope `bookings:manage` or `messages:read`) gives every day of a range with its free start times, as the customer would see them: the opening hours, closed days, booked appointments, blocked time and the busy time of your connected calendar are already applied.

    | Query | What to fill in |
    | --- | --- |
    | `service_id` | The service from step 1 |
    | `from`, `to` | The first and last day, `YYYY-MM-DD` in the business time zone. Default: today and 6 days on; at most 32 days |
    | `provider_id` | One staff member's own times. Left out: anyone available |
    | `addons` | A comma list of the service's add-on ids: only times long enough for them |
    | `seats` | On a group service: the places wanted (1 + guests) |

    <CodeGroup>

    ```bash cURL
    curl "https://api.app2email.com/v1/YOUR_NUMBER/bookings/availability?service_id=haircut&from=2026-11-10&to=2026-11-11" \
      -H "Authorization: Bearer YOUR_API_KEY"
    ```

    ```javascript Node.js
    const q = new URLSearchParams({ service_id: "haircut", from: "2026-11-10", to: "2026-11-11" });
    const res = await fetch(`${API}/bookings/availability?${q}`, { headers });
    const { days } = await res.json();
    for (const day of days) console.log(day.date, day.slots.map((s) => s.title));
    ```

    ```python Python
    res = requests.get(f"{API}/bookings/availability", headers=HEADERS, timeout=10,
                       params={"service_id": "haircut", "from": "2026-11-10", "to": "2026-11-11"})
    for day in res.json()["days"]:
        print(day["date"], [s["title"] for s in day["slots"]])
    ```

    </CodeGroup>

    **What you get back:**

    ```json
    {
      "success": true,
      "request_id": "a9xw1",
      "timezone": "Australia/Sydney",
      "enabled": true,
      "days": [
        {
          "date": "2026-11-10",
          "slots": [
            { "id": "2026-11-10T09:00", "title": "9:00 AM", "start": "2026-11-09T22:00:00.000Z", "end": "2026-11-09T22:30:00.000Z", "providers": ["maria", "tom"] },
            { "id": "2026-11-10T09:30", "title": "9:30 AM", "start": "2026-11-09T22:30:00.000Z", "end": "2026-11-09T23:00:00.000Z", "providers": ["tom"] }
          ]
        },
        { "date": "2026-11-11", "slots": [] }
      ]
    }
    ```

    - Show `title` to the customer and keep the slot's `id`: it is the local time in the business time zone (`yyyy-MM-ddTHH:mm`) that the next calls take as `start`. `start` and `end` are the same time in UTC.
    - `providers` names the staff members free at that time.
    - A day with an empty `slots` list is full or closed. A full day is where the [waitlist](#the-waitlist) helps.

    **Only "the next free times"?** `GET /bookings/next?service_id=haircut&count=3` gives the next free start times across days (at most 60 days ahead), for a "Next free: tomorrow 9:00" button:

    ```json
    {
      "success": true,
      "request_id": "c8nx9",
      "slots": [
        { "id": "2026-11-12T09:00", "date": "2026-11-12", "title": "9:00 AM", "start": "2026-11-11T22:00:00.000Z", "end": "2026-11-11T22:30:00.000Z", "providers": ["maria"] }
      ],
      "count": 1,
      "timezone": "Australia/Sydney",
      "enabled": true
    }
    ```
  </Step>
  <Step title="Hold the time while the customer types">
    Optional, but it saves the customer from "sorry, that time is gone". `POST /bookings/holds` (scope `bookings:manage`) keeps a free time for `minutes` (1 to 30, default 10). While it is held it counts as taken everywhere: in the availability, the calendar and every booking check, also for customers booking on WhatsApp.

    ```bash
    curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/holds \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: hold-session-8f2c1a" \
      -d '{"service_id": "haircut", "start": "2026-11-10T09:00", "provider_id": "maria", "minutes": 10}'
    ```

    **What you get back** (201 Created):

    ```json
    {
      "success": true,
      "request_id": "f1hc2",
      "hold": {
        "reference": "BK-7Q3M2A",
        "status": "held",
        "service_id": "haircut",
        "provider_id": "maria",
        "contact": "",
        "name": "",
        "start": "2026-11-09T22:00:00.000Z",
        "end": "2026-11-09T22:30:00.000Z",
        "start_local": "2026-11-10T09:00",
        "end_local": "2026-11-10T09:30",
        "expires": "2026-11-09T04:10:00.000Z",
        "source": "api"
      },
      "note": "The time is kept until hold.expires: nobody else can book it."
    }
    ```

    Show a countdown to `expires`. If the customer leaves, `DELETE /bookings/holds/{reference}` frees the time at once; otherwise it frees itself at `expires`. A time that went in the meantime answers 409 `booking_slot_taken`: read the availability again.
  </Step>
  <Step title="Book it">
    `POST /bookings` (scope `bookings:manage`) books the appointment.

    | Field | What to fill in |
    | --- | --- |
    | `contact` | The customer's WhatsApp number, country code first, digits only (or their business-scoped user id) |
    | `name` | The customer's name |
    | `service_id`, `start` | The service and the slot `id` from step 2 |
    | `hold` | The hold's `reference` from step 3, if you held the time. The booking takes the hold's reference and frees the hold |
    | `provider_id` | The staff member. Left out: the first free one |
    | `email`, `notes` | Optional. With an email, the customer can also get the confirmation by email (when customer emails are on in Book-and-Pay) |
    | `answers_q` | The answers to the service's own questions, by question id. Required questions must be answered |
    | `notify` | `true` (the default) sends the WhatsApp confirmation. `false` books silently |
    | Header `Idempotency-Key` | A value unique to this booking, eg your form submission id. The same request with the same key within 24 hours books nothing twice |

    <CodeGroup>

    ```bash cURL
    curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: booking-form-8f2c1a" \
      -d '{
        "contact": "61412345678",
        "name": "John Smith",
        "email": "john@example.com",
        "service_id": "haircut",
        "start": "2026-11-10T09:00",
        "provider_id": "maria",
        "hold": "BK-7Q3M2A",
        "notes": "First visit",
        "notify": true
      }'
    ```

    ```javascript Node.js
    async function book({ formId, phone, name, email, serviceId, slotId, providerId, holdRef }) {
      const res = await fetch(`${API}/bookings`, {
        method: "POST",
        headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": `booking-${formId}` },
        body: JSON.stringify({
          contact: phone, // digits only, country code first
          name, email,
          service_id: serviceId,
          start: slotId, // eg "2026-11-10T09:00"
          provider_id: providerId,
          hold: holdRef, // leave out when you did not hold the time
          notify: true,
        }),
      });
      const json = await res.json();
      if (res.status === 409 && json.error?.code === "booking_slot_taken") return { taken: true };
      if (!res.ok) throw new Error(`${json.error?.code}: ${json.error?.how_to_fix} (${json.request_id})`);
      return json.booking; // keep booking.id and booking.reference
    }
    ```

    ```python Python
    def book(form_id, phone, name, email, service_id, slot_id, provider_id=None, hold_ref=None):
        body = {"contact": phone, "name": name, "email": email, "service_id": service_id,
                "start": slot_id, "notify": True}
        if provider_id:
            body["provider_id"] = provider_id
        if hold_ref:
            body["hold"] = hold_ref
        res = requests.post(f"{API}/bookings", json=body, timeout=10,
                            headers={**HEADERS, "Idempotency-Key": f"booking-{form_id}"})
        data = res.json()
        if res.status_code == 409 and data.get("error", {}).get("code") == "booking_slot_taken":
            return None  # show the free times again
        if not res.ok:
            raise RuntimeError(f"{data['error']['code']}: {data['error']['how_to_fix']} ({data['request_id']})")
        return data["booking"]  # keep booking["id"] and booking["reference"]
    ```

    </CodeGroup>

    **What you get back** (201 Created):

    ```json
    {
      "success": true,
      "request_id": "b2mz7",
      "booking": {
        "id": 42,
        "reference": "BK-7Q3M2A",
        "status": "confirmed",
        "contact": "61412345678",
        "contact_name": "John Smith",
        "contact_email": "john@example.com",
        "service": { "id": "haircut", "name": "Haircut", "duration_min": 30 },
        "start": "2026-11-09T22:00:00.000Z",
        "end": "2026-11-09T22:30:00.000Z",
        "timezone": "Australia/Sydney",
        "source": "api",
        "calendar": { "provider": "google", "event_id": "evt_1a2b3c", "url": "https://calendar.google.com/calendar/event?eid=..." },
        "answers": {},
        "notes": "First visit",
        "provider": { "id": "maria", "name": "Maria" },
        "credits_used": 0,
        "created": "2026-11-06T01:12:09.000Z"
      },
      "note": "Booked. The customer gets the confirmation on WhatsApp (a text inside their 24 hour window, else the booking confirmation template)."
    }
    ```

    Keep `id` and `reference` with your own record. Every later call takes either one; `reference` is the short code the customer sees. A repeated request with the same `Idempotency-Key` gets this same answer again with the header `Idempotent-Replayed: true`.

    The start must be a slot from step 2. Your own minimum notice is not checked on `POST /bookings`, so offer the customer only the times the availability gives (what a customer would see).
  </Step>
</Steps>

## The result

**On WhatsApp:**

1. Within seconds the customer gets the confirmation in your words (the "Messages" part of Book-and-Pay), with a calendar file when you switched that on. If they have not written to your number in the last 24 hours, the confirmation goes out as the booking confirmation template instead, so a customer who has never written to you still gets it.
2. Before the appointment a reminder arrives with **Confirm**, **Reschedule** and **Cancel** buttons. Reminders usually go out when the 24 hour window is closed, so Book-and-Pay uses its approved utility templates for them.
3. A tap on Confirm fills the booking's `attendance_confirmed` with the time. A tap on Cancel, or a reply CANCEL, cancels the appointment and sends `booking.cancelled` with `cancelled.by: "customer"`. Reschedule lets the customer pick a new time, and you get `booking.rescheduled`.

**For you:** the event in your calendar (`calendar.url`), an email to the address in your Book-and-Pay messages, and this webhook event:

```json
{
  "id": "evt_Bk3k9m2Lw8Rt5Yp1Zs01",
  "type": "booking.created",
  "created": "2026-11-06T01:00:00.000Z",
  "number": "4976659348270",
  "data": {
    "id": 42,
    "reference": "BK-7Q3M2A",
    "status": "confirmed",
    "contact": "61412345678",
    "contact_name": "John Smith",
    "contact_email": "john@example.com",
    "service": { "id": "haircut", "name": "Haircut", "duration_min": 30 },
    "start": "2026-11-09T22:00:00.000Z",
    "end": "2026-11-09T22:30:00.000Z",
    "timezone": "Australia/Sydney",
    "source": "api",
    "calendar": { "provider": "google", "event_id": "evt_1a2b3c", "url": "https://calendar.google.com/calendar/event?eid=..." },
    "answers": {},
    "notes": "First visit",
    "provider": { "id": "maria", "name": "Maria" },
    "credits_used": 0,
    "created": "2026-11-06T01:00:00.000Z",
    "timestamp": "2026-11-06T01:00:00.000Z",
    "hold": true
  }
}
```

`source` tells you where the booking came from: `api` (you), `whatsapp_flow` (the customer in the WhatsApp booking form), `web` (the online booking page) or `dashboard` (your team, also in the calendar app). `hold: true` means it was made from a held time. If the calendar write failed, `calendar.error` says why; the booking still stands.

## Change, move or cancel an appointment

### Find it

- `GET /bookings/{id}` takes the id or the reference: `GET /bookings/BK-7Q3M2A`.
- `GET /bookings?contact=61412345678&upcoming=true` lists one customer's confirmed appointments from now on, soonest first, for a "My appointments" page.
- `GET /bookings?from=2026-11-10&to=2026-11-16` lists a range of days (`status`, `provider_id`, `q` and `order=desc` filter more; page with `next_cursor` and `cursor`).

### Move it to another time

`POST /bookings/{id}/reschedule` (scope `bookings:manage`) moves a confirmed appointment in place: the same `id` and `reference`, the calendar event moved, the reminders start again. `start` must be a free slot from `GET /bookings/availability` or `GET /bookings/next`; the appointment's own time counts as free. `provider_id` changes the staff member too (`"any"`: the first free one).

<CodeGroup>

```bash cURL
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A/reschedule \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: move-BK-7Q3M2A-2026-11-12T10:00" \
  -d '{"start": "2026-11-12T10:00", "notify": true}'
```

```javascript Node.js
const res = await fetch(`${API}/bookings/BK-7Q3M2A/reschedule`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": "move-BK-7Q3M2A-2026-11-12T10:00" },
  body: JSON.stringify({ start: "2026-11-12T10:00", notify: true }),
});
console.log(res.status, (await res.json()).booking);
```

```python Python
res = requests.post(f"{API}/bookings/BK-7Q3M2A/reschedule", timeout=10,
                    headers={**HEADERS, "Idempotency-Key": "move-BK-7Q3M2A-2026-11-12T10:00"},
                    json={"start": "2026-11-12T10:00", "notify": True})
print(res.status_code, res.json().get("booking"))
```

</CodeGroup>

**What you get back** (200; shortened, `booking` has the same fields as above):

```json
{
  "success": true,
  "request_id": "c0rs2",
  "booking": {
    "id": 42,
    "reference": "BK-7Q3M2A",
    "status": "confirmed",
    "start": "2026-11-11T23:00:00.000Z",
    "end": "2026-11-11T23:30:00.000Z",
    "timezone": "Australia/Sydney",
    "provider": { "id": "maria", "name": "Maria" }
  },
  "note": "Moved. The booking keeps its id and reference. The customer is told on WhatsApp."
}
```

The customer gets the new time on WhatsApp unless `notify` is false, and your webhook gets `booking.rescheduled`. 409 `booking_slot_taken`: the time is not free, read the availability again.

### Change the details

`PATCH /bookings/{id}` (scope `bookings:manage`) changes the customer's `name` or `email`, the `notes`, the `answers` or the staff member (`provider_id`; the time must be free for them, else 409 `booking_slot_taken`). The time itself only changes with `reschedule`. `booking.updated` is sent with `changed` naming the fields.

```bash
curl -X PATCH https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"notes": "Allergic to ammonia", "provider_id": "tom"}'
```

### Cancel it

`POST /bookings/{id}/cancel` (scope `bookings:manage`) removes the calendar event, sends `booking.cancelled`, and tells the customer on WhatsApp (a text inside their 24 hour window, else the cancellation template) unless `notify` is false.

```bash
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A/cancel \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reason": "customer asked by phone", "notify": true}'
```

**What you get back** (200; shortened):

```json
{
  "success": true,
  "request_id": "b3nd4",
  "booking": {
    "id": 42,
    "reference": "BK-7Q3M2A",
    "status": "cancelled",
    "cancelled": { "at": "2026-11-07T03:00:00.000Z", "by": "api", "reason": "customer asked by phone" }
  },
  "note": "Cancelled. The customer is told on WhatsApp (a text inside their 24 hour window, else the cancellation template)."
}
```

Cancelling twice answers 409 `booking_cancelled`: treat it as done. A cancellation frees the time, and customers on that day's waitlist get offered it.

### After the visit

`POST /bookings/{id}/status` with `{"status": "completed"}` or `{"status": "no_show"}` marks the appointment (`"confirmed"` puts it back). A completed appointment gets the follow-up message (aftercare and the rating buttons) when you switched it on; a rating comes as `booking.rated`. An appointment you do not mark is completed by itself 24 hours after its end.

## Block time

Lunch, a day off, a closed afternoon: `POST /calendar/blocks` (scope `bookings:manage`) makes time that no one can book, for one staff member (`provider_id`) or the whole business (leave it out). Give `start` and `end` (local time `yyyy-MM-ddTHH:mm`, at most 31 days long), or `date` for one whole day. Existing appointments are not touched.

<CodeGroup>

```bash cURL
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/calendar/blocks \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: lunch-maria-2026-11-14" \
  -d '{"start": "2026-11-14T12:00", "end": "2026-11-14T13:00", "provider_id": "maria", "title": "Lunch"}'
```

```javascript Node.js
const res = await fetch(`${API}/calendar/blocks`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": "lunch-maria-2026-11-14" },
  body: JSON.stringify({ start: "2026-11-14T12:00", end: "2026-11-14T13:00", provider_id: "maria", title: "Lunch" }),
});
const { block } = await res.json();
console.log(block.id);
```

```python Python
res = requests.post(f"{API}/calendar/blocks", timeout=10,
                    headers={**HEADERS, "Idempotency-Key": "lunch-maria-2026-11-14"},
                    json={"start": "2026-11-14T12:00", "end": "2026-11-14T13:00",
                          "provider_id": "maria", "title": "Lunch"})
print(res.json()["block"]["id"])
```

</CodeGroup>

**What you get back** (201 Created):

```json
{
  "success": true,
  "request_id": "c3bk4",
  "block": {
    "id": 3,
    "provider_id": "maria",
    "title": "Lunch",
    "notes": "",
    "start": "2026-11-14T01:00:00.000Z",
    "end": "2026-11-14T02:00:00.000Z",
    "start_local": "2026-11-14T12:00",
    "end_local": "2026-11-14T13:00",
    "source": "api",
    "created_by": "API key Planner",
    "created": "2026-11-11T01:12:09.000Z",
    "updated": "2026-11-11T01:12:09.000Z"
  },
  "note": "Blocked. No one can book that time."
}
```

- `PATCH /calendar/blocks/{id}` changes any of `start`, `end`, `date`, `provider_id`, `title`, `notes`.
- `DELETE /calendar/blocks/{id}` removes it: the time can be booked again, and waiting customers can be offered it.
- `GET /calendar/blocks?from=2026-11-14&to=2026-11-20` lists the blocks.
- `GET /calendar` gives everything for a range of days in one answer (at most 62 days): appointments, blocks, the busy time of your connected calendar, the times held right now, the opening hours per day, the staff and the services. Good for a staff screen in your own app.

The events are `calendar.block.created` and `calendar.block.deleted`.

<a id="the-waitlist"></a>

## The waitlist

When a day has no free time left, the customer can wait for one. Switch the waitlist on for the service in Book-and-Pay first (`config.services[].waitlist` in `GET /settings/booking`).

`POST /bookings/waitlist` (scope `bookings:manage`) puts a customer on the waitlist of a full day:

```bash
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/waitlist \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contact": "61412345678", "name": "Jane", "service_id": "haircut", "date": "2026-11-20"}'
```

**What you get back** (201 Created; shortened):

```json
{
  "success": true,
  "request_id": "w2add",
  "entry": {
    "id": 12,
    "reference": "WL-4HT9XC",
    "status": "waiting",
    "service_id": "haircut",
    "service_name": "Haircut",
    "provider_id": "maria",
    "provider_name": "Maria",
    "date": "2026-11-20",
    "date_label": "Fri 20 Nov 2026",
    "contact": "61412345678",
    "contact_name": "Jane",
    "seats": 1,
    "source": "api",
    "notified_count": 0,
    "appointment_id": null
  },
  "existing": false
}
```

- One active entry per customer, service and day: asking again answers 200 with that entry and `existing: true`, so the call is safe to repeat.
- `provider_id` waits for one staff member; left out, anyone. `slot_id` waits for one full time of a group service, `seats` for more than one place. `email` lets the offer go by email when WhatsApp cannot be used.
- The day must be bookable and have no free time left, else 409 `waitlist_not_offered`: offer the free times instead. `force: true` skips the free-time check.

**What happens next:** when a time opens on that day (a cancellation, a move, a removed block, and a check every 5 minutes), the waiting customers get a WhatsApp message with a link to book it (the waitlist template when their window is closed, or an email). The first one to book gets it. Your webhook gets `waitlist.notified` with the `offer`:

```json
{
  "id": "evt_Wl3k9m2Lw8Rt5Yp1Zs02",
  "type": "waitlist.notified",
  "created": "2026-11-13T01:00:00.000Z",
  "number": "4976659348270",
  "data": {
    "id": 12,
    "reference": "WL-4HT9XC",
    "status": "notified",
    "service_id": "haircut",
    "service_name": "Haircut",
    "provider_id": "maria",
    "provider_name": "Maria",
    "date": "2026-11-20",
    "date_label": "Fri 20 Nov 2026",
    "slot_id": "",
    "time_label": "",
    "contact": "61412345678",
    "contact_name": "Jane",
    "contact_email": "",
    "seats": 1,
    "source": "api",
    "notified_count": 1,
    "notified_at": "2026-11-13T01:00:00.000Z",
    "appointment_id": null,
    "note": "Offered Fri 20 Nov 2026 10:30 AM on WhatsApp",
    "created": "2026-11-13T01:00:00.000Z",
    "updated": "2026-11-13T01:00:00.000Z",
    "day": "2026-11-20",
    "slot_local": "",
    "contact_masked": "•••• 5678",
    "created_at": "2026-11-13T01:00:00.000Z",
    "timestamp": "2026-11-13T01:00:00.000Z",
    "offer": {
      "slot_id": "2026-11-20T10:30",
      "start": "2026-11-19T23:30:00.000Z",
      "date_label": "Fri 20 Nov 2026",
      "time_label": "10:30 AM",
      "channel": "whatsapp",
      "manual": false
    }
  }
}
```

An entry's `status` is `waiting`, `notified` (offered a time, up to 3 offers), `booked` (the customer booked that service that day; `appointment_id` is the booking), `expired` (the day passed), `removed`, or `pending_confirm` (joined on your public booking page and not confirmed on WhatsApp yet).

- `GET /bookings/waitlist` lists the active entries, soonest day first (`from`, `to`, `service_id`, `contact`, `include_closed=true`).
- `POST /bookings/waitlist/{reference}/remove` takes a customer off it without a message to them, and sends `waitlist.removed`.

## Booking webhook events

Register a webhook once with `POST /webhooks` (scope `webhooks:manage`), or on the API key page. Every webhook of the number gets every event: pick the ones you need by `type` and answer 2xx to the rest. [Build a WhatsApp chatbot with the API](/guides/how-to-whatsapp-chatbot) shows the registration, the signature check and a test event step by step; `POST /webhooks/{id}/test` with `{"type": "booking.created"}` sends that event's sample.

| Event | When |
| --- | --- |
| `booking.created` | An appointment was booked: in the WhatsApp form, on the online page, on the dashboard, or through the API |
| `booking.rescheduled` | An appointment was moved; the old time is in `rescheduled_from` |
| `booking.cancelled` | An appointment was cancelled; `cancelled.by` is `customer`, `business`, `api` or `system` |
| `booking.updated` | Name, email, notes, answers or staff member changed; `changed` names the fields |
| `booking.rated` | The customer rated a completed appointment |
| `booking.paid`, `booking.refunded` | The online payment or deposit of an appointment was paid, or refunded |
| `booking.note.created` | An internal note was added |
| `calendar.block.created`, `calendar.block.deleted` | Time was blocked, or a block removed |
| `waitlist.joined`, `waitlist.notified`, `waitlist.removed` | A customer joined the waitlist, was offered a time, or was taken off |

The events come for every booking, not only the ones you made: a customer who books in the WhatsApp form or cancels with a reply also reaches your system. `booking.rescheduled` looks like this:

```json
{
  "id": "evt_Bk3k9m2Lw8Rt5Yp1Zs03",
  "type": "booking.rescheduled",
  "created": "2026-11-06T01:00:00.000Z",
  "number": "4976659348270",
  "data": {
    "id": 42,
    "reference": "BK-7Q3M2A",
    "status": "confirmed",
    "contact": "61412345678",
    "contact_name": "Sample Contact",
    "contact_email": "sample@example.com",
    "service": { "id": "haircut", "name": "Haircut", "duration_min": 30 },
    "start": "2026-11-09T23:00:00.000Z",
    "end": "2026-11-09T23:30:00.000Z",
    "timezone": "Australia/Sydney",
    "source": "whatsapp_flow",
    "calendar": { "provider": "google", "event_id": "evt_sample_1", "url": "https://calendar.google.com/calendar/event?eid=sample" },
    "answers": { "notes": "Please keep it short" },
    "notes": "Please keep it short",
    "provider": { "id": "maria", "name": "Maria" },
    "credits_used": 0,
    "created": "2026-11-06T01:00:00.000Z",
    "timestamp": "2026-11-06T01:00:00.000Z",
    "rescheduled_from_id": 41,
    "rescheduled_from": { "id": 41, "reference": "BK-2KD8XQ", "start": "2026-11-08T23:00:00.000Z", "end": "2026-11-08T23:30:00.000Z" }
  }
}
```

A move through the API keeps the id and the reference. A customer who reschedules on WhatsApp gets a new appointment that replaces the old one, as in this sample: find your record by `rescheduled_from.id` (or its `reference`) and store the new `id` and `reference`.

## Deposits and payments

Book-and-Pay takes payments through your own Stripe or PayPal account, connected on its Payments page: a price per service, payment required, optional or none, and a deposit if you want one. To ask for a deposit or another amount on an appointment, `POST /payments/links` with the appointment's `booking_id` makes a payment page; with `send: true` and the customer inside their 24 hour window they also get it in the chat with a **Pay** button. When the provider confirms it, your webhook gets `payment.paid`; the appointment's own online payment or deposit (set on the service) reports `booking.paid`. Step by step: [Ask for a payment inside a WhatsApp chat](/guides/how-to-payment-links).

## Let the customer book by themselves

You do not have to build every screen yourself:

- **A personal booking link:** `POST /bookings/links` with the customer's `contact` makes a link to the online booking page (switch it on in Book-and-Pay, Online booking tab). `purpose` `book`, `reschedule` (with `booking_id`) or `manage` (their upcoming appointments). The answer's `link.url` is yours to send.
- **The booking form inside WhatsApp:** `POST /flows/{key}/send` with `{"contact": "61412345678"}` sends the published booking form to a customer who wrote to you in the last 24 hours. The booking comes back as `booking.created` with `source: "whatsapp_flow"`.

Both end in the same appointments, confirmations, reminders and events as the calls above.

## Production checklist

<Check>
**Keep the key on your server.** Your web page or app talks to your server, and only your server calls app2email. A key that only shows free times needs `messages:read`; the key that books needs `bookings:manage`. A key can be limited to your server's IP addresses, have a daily cap, or expire.
</Check>

<Check>
**Book each appointment once.** Send an `Idempotency-Key` with `POST /bookings`, `POST /bookings/holds`, `POST /bookings/{id}/reschedule` and `POST /calendar/blocks`, built from something unique on your side (the form submission id). Same key and same body within 24 hours: the first answer comes back with `Idempotent-Replayed: true`. Same key, other body: 422 `idempotency_key_reused`. 409 `idempotency_request_in_progress`: wait and retry with the same key. `POST /bookings/waitlist` needs no key: a repeat answers `existing: true`.
</Check>

<Check>
**Expect a time to go.** Between showing the times and booking, someone on WhatsApp can take the slot. Hold it with `POST /bookings/holds`, and on 409 `booking_slot_taken` show the free times again rather than an error page.
</Check>

<Check>
**Get the time zone right.** Slot ids and `start` in requests are local times in the business time zone (`timezone` in every answer); `start` and `end` in answers and events are UTC. Show the customer `title`, `start_local` or the business time zone, not their own browser's.
</Check>

<Check>
**Verify every event.** Check `X-App2email-Signature` over the raw body with the webhook's `whsec_...` secret, and refuse a `t` older than 5 minutes. Answer 2xx within 10 seconds; a failed event is sent again for about 32 hours.
</Check>

<Check>
**Dedupe on real ids.** Drop repeated events by the event `id` (also in `X-App2email-Delivery`). Store appointments by their `id` and `reference`, and follow `rescheduled_from` when a customer moves one on WhatsApp. Events can arrive out of order: compare `timestamp`.
</Check>

<Check>
**Respect the limits.** Every answer has `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` and `X-RateLimit-Policy`. Over the limit: 429 `rate_limited` with `Retry-After`; wait that long, then retry. Cache the services and read the availability when the customer opens the page, not on every key press. Ranges: at most 32 days for `availability`, 62 for `calendar`. See [Limits](/api/limits).
</Check>

<Check>
**Let Book-and-Pay do the messages.** The confirmation, the reminders and the moved and cancelled notices use free text inside the 24 hour window and Book-and-Pay's approved utility templates outside it. Check on the Templates page that Meta approved them before you go live. Send `notify: false` only when you tell the customer yourself, and tell customers on your form that the confirmation and reminders come on WhatsApp.
</Check>

<Check>
**Ask before marketing.** Confirmations and reminders are about the appointment the customer booked. A "time for your next visit" message is marketing: send it only to customers who agreed to marketing, and the Do Not Call list applies.
</Check>

## If it does not work

| What you see | Why | Fix |
| --- | --- | --- |
| 403 `booking_not_enabled` | Book-and-Pay is not set up for this number yet | Set it up and switch it on on the Book-and-Pay page (https://www.app2email.com/dashboard/app/book). If it is on and the error stays, write to support@app2email.com with the `request_id` |
| 403 `insufficient_scope` | The key lacks `bookings:manage` (or `messages:read` for reads) | Make a key with that scope on the API key page; the Default key does not have it |
| 403 `sandbox_key` | A sandbox key cannot book, hold, move, cancel, block or change the waitlist | Use a normal key; keep the sandbox key for the read calls |
| 403 `not_in_instant_sandbox` | The demo number has no booking calls | Use your own number with Book-and-Pay set up |
| 401 `missing_api_key`, `invalid_api_key`, `api_key_revoked` | No key, a wrong key, or an old one | Send `Authorization: Bearer YOUR_API_KEY`, with the number of that key in the URL |
| 403 `plan_not_allowed`, `service_not_live` | No paid plan, or the service is paused | Choose a plan; a paused service goes live with "Go Live" on the Settings page |
| 400 `invalid_service` | `service_id` is missing or not a switched-on service | Take an `id` from `GET /bookings/services` |
| 400 `invalid_start` | `start` is missing or not a slot | Send a slot `id` (`yyyy-MM-ddTHH:mm`, business time zone) from `GET /bookings/availability` |
| 400 `invalid_answers` | A required question of the service is not answered | Send every required question in `answers_q` |
| 400 `invalid_addons`, `invalid_guests` | An add-on the service does not offer, or too many guests or seats | Use the service's own add-on ids; keep guests within the service's maximum |
| 400 `invalid_range`, `range_too_large` | `from` is after `to`, or the range is too long | At most 32 days for availability, 62 for the calendar |
| 400 `invalid_block` | The end is not after the start, the block is over 31 days, or the staff member does not exist | Fix the fields the message names; `provider_id` comes from `GET /bookings/staff` |
| 404 `booking_not_found`, `block_not_found`, `hold_not_found`, `waitlist_not_found` | No such appointment, block, hold or waitlist entry on this number | Check the id or reference (`BK-...`, `WL-...`) and the number in the URL |
| 409 `booking_slot_taken` | The time is not free any more | Read the availability again and let the customer pick another time |
| 409 `hold_expired` | The held time expired, was released, or was already booked | Hold the time again, or read the booking it became |
| 409 `booking_cancelled` | The appointment is already cancelled | Nothing to do; make a new booking if the customer wants another time |
| 409 `waitlist_not_offered` | The service has no waitlist, the day still has free times, is closed or too far ahead, or its waitlist is full | Switch the waitlist on for the service, pick a full day (or send `force: true`), or book a free time instead |
| 409 `waitlist_not_set_up` | The waitlist is not available yet on our side | Try again later |
| 403 `link_not_usable` | A booking link expired, was revoked or used up, or the online booking page is off | Make a new link with `POST /bookings/links`, or switch the online page on |
| 422 `idempotency_key_reused` | The same `Idempotency-Key` with a different body | Use a new key for a different booking |
| 429 `rate_limited` | Too many calls for this key | Wait `Retry-After` seconds, then retry |
| The customer got no WhatsApp confirmation | `notify` was false, or the booking template is not approved yet | Check the Templates page; `message.status` and `message.failed` events show what happened to the message |

Every answer has a `request_id`. `GET /requests/{id}` shows what was logged for it, and support@app2email.com can find it too. All codes: [Errors](/api/errors).

## FAQ

<AccordionGroup>
  <Accordion title="Does it work with my staff and their own calendars?">
    Yes. Staff members are set up in Book-and-Pay, each with their own hours and, if they like, their own calendar. `GET /bookings/staff` lists them, `provider_id` asks for one person's times or books with them, and leaving it out means "anyone available". Busy time in a connected calendar is never offered.
  </Accordion>
  <Accordion title="Can a customer book a group class or bring someone?">
    Yes, when the service has places. `GET /bookings/availability` with `seats` shows only times with that many places left, and `POST /bookings` takes `guests`. A full group time can have its own waitlist (`slot_id` on `POST /bookings/waitlist`).
  </Accordion>
  <Accordion title="Can an AI agent book appointments instead of my code?">
    Yes. The MCP servers `https://api.app2email.com/mcp/book-and-pay` and `https://api.app2email.com/mcp/calendar` have the same calls as tools (`get_booking_availability`, `create_booking`, `cancel_booking`, `find_next_booking_slots`, `hold_booking_slot`, `reschedule_booking`, `create_time_block`, `add_to_waitlist` ...). See [Let an AI agent run your WhatsApp with MCP](/guides/how-to-ai-agent-mcp) and [MCP](/api/mcp).
  </Accordion>
</AccordionGroup>

## More how-to guides

<CardGroup cols={2}>
  <Card title="Ask for a payment inside a WhatsApp chat" href="/guides/how-to-payment-links">
    Send a Pay button for a deposit and hear when it is paid.
  </Card>
  <Card title="Send order and appointment notifications with templates" href="/guides/how-to-order-notifications">
    Approved utility templates for your own confirmations and reminders.
  </Card>
  <Card title="Collect details with a WhatsApp Flow form" href="/guides/how-to-whatsapp-flow-form">
    A form inside WhatsApp, with the answers sent to your system.
  </Card>
  <Card title="Let an AI agent run your WhatsApp with MCP" href="/guides/how-to-ai-agent-mcp">
    Connect an agent that finds free times and books for your customers.
  </Card>
</CardGroup>

[All how-to guides](https://www.app2email.com/docs#how-to)
