> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keebai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /v1/scheduling/booking/resource-bookings

> Book a resource for a customer: a stay on a night resource, or a time block on a block resource.

Creates a resource booking on behalf of a customer. The body depends on the resource's `booking_unit` (see [GET resources](https://docs.keebai.com/dev/endpoints/scheduling-resources-list.md)):

* **Night resource**: `check_in` and `check_out`, and optionally the arrival and departure times.
* **Block resource**: `date`, `start_time` and optionally `duration_minutes`.

Sending night fields to a block resource, or the other way around, returns `400 RESOURCE_BOOKING_UNIT_MISMATCH`.

Keebai checks the whole stay again when you book (windows, minimum and maximum nights, notice, party size and room every night), so a quote that went stale returns `409 STAY_FULL` instead of overbooking. The customer is found or created in the CRM by phone. The booking is recorded with source `api`.

**Prepayment.** When the resource asks for a prepayment, the booking lands in `awaiting_payment` with a payment link for that amount and a hold. It occupies its nights until the hold expires; if the customer has not paid by then, Keebai cancels it. Without a prepayment it lands in `booked`.

## Endpoint

```
POST https://api.keebai.com/v1/scheduling/booking/resource-bookings
```

## Required scope

`scheduling:appointments:create`

## Headers

* `Authorization: Bearer kbai_pk_<token>`. Required.
* `Content-Type: application/json`. Required.
* `Idempotency-Key`: required. 1 to 128 letters, digits, `-` or `_`. A retry with the same key returns the first booking instead of creating another.

## Body: stay on a night resource

```json theme={"system"}
{
  "branch_id": "665f00000000000000000b01",
  "resource_id": "665f00000000000000000a01",
  "check_in": "2026-12-03",
  "check_out": "2026-12-05",
  "check_in_time": "11:00",
  "check_out_time": null,
  "party_size": 1,
  "customer": {
    "name": "Valentina",
    "last_name": "Rojas",
    "phone": "+56987654321",
    "email": "valentina@example.com",
    "customer_id": null
  },
  "notes": "Rocky, mestizo, 12 kg."
}
```

* `resource_id`, `check_in`, `check_out`, `customer.name` and `customer.phone`: required.
* `branch_id`: optional. Defaults to the resource's branch.
* `check_in_time`: arrival time, inside the day's check-in window. Omitted or `null`: the stay starts when the window opens.
* `check_out_time`: departure time, inside the day's check-out window. Omitted or `null`: the stay ends when the window closes.
* `party_size`: guests. Defaults to 1.
* `customer.customer_id`: the CRM customer id, when you already have it.
* `notes`: shown to the business on the booking (max 1000 characters).

## Body: block on a block resource

```json theme={"system"}
{
  "resource_id": "665f00000000000000000a03",
  "date": "2026-12-03",
  "start_time": "19:00",
  "duration_minutes": 90,
  "party_size": 4,
  "customer": { "name": "Tomás", "last_name": "Soto", "phone": "+56911112222" }
}
```

* `date` and `start_time` must be a block that [GET resources/availability](https://docs.keebai.com/dev/endpoints/scheduling-resource-availability.md) offers.
* `duration_minutes`: one of the resource's `durations_minutes`. Defaults to the first one.

`origin`, `agent` and any other field are rejected with `400`: the public API always books as `api`.

## Example request

```bash curl theme={"system"}
curl -X POST https://api.keebai.com/v1/scheduling/booking/resource-bookings \
  -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: stay-6b0a1e00-20261203" \
  -d '{
    "resource_id": "665f00000000000000000a01",
    "check_in": "2026-12-03",
    "check_out": "2026-12-05",
    "customer": { "name": "Valentina", "last_name": "Rojas", "phone": "+56987654321" }
  }'
```

```python Python theme={"system"}
import os, requests

resp = requests.post(
    "https://api.keebai.com/v1/scheduling/booking/resource-bookings",
    headers={
        "Authorization": f"Bearer {os.environ['KEEBAI_API_TOKEN']}",
        "Idempotency-Key": "stay-6b0a1e00-20261203",
    },
    json={
        "resource_id": resource_id,
        "check_in": "2026-12-03",
        "check_out": "2026-12-05",
        "customer": {"name": "Valentina", "last_name": "Rojas", "phone": "+56987654321"},
    },
    timeout=10,
)
resp.raise_for_status()
booking = resp.json()["booking"]
```

## Response

### 201 Created: stay

```json theme={"system"}
{
  "customer_id": "665f00000000000000000e01",
  "branch": { "name": "Sucursal Centro", "address": "Av. Siempre Viva 742" },
  "booking": {
    "id": "665f00000000000000000c01",
    "kind": "resource_booking",
    "number": 1042,
    "booking_unit": "night",
    "branch_id": "665f00000000000000000b01",
    "branch_name": "Sucursal Centro",
    "resource_id": "665f00000000000000000a01",
    "resource_name": "Suite canina · Mediana",
    "customer_id": "665f00000000000000000e01",
    "contact": { "name": "Valentina", "last_name": "Rojas" },
    "party_size": 1,
    "start": "2026-12-03T14:00:00.000Z",
    "end": "2026-12-05T17:30:00.000Z",
    "time_zone": "America/Santiago",
    "check_in": "2026-12-03",
    "check_in_time": "11:00",
    "check_out": "2026-12-05",
    "check_out_until": "14:30",
    "nights": 2,
    "label": "Ingreso jue 3 dic · Retiro sáb 5 dic · 2 noches",
    "price": 40000,
    "currency": "CLP",
    "prepayment": 16000,
    "amount_paid": 0,
    "balance": 40000,
    "payment_status": "pending",
    "payment_link": "https://pay.keebai.com/p/K7Q2M",
    "payment_hold_expires_at": "2026-11-26T17:10:00.000Z",
    "status": "awaiting_payment",
    "notes": "Rocky, mestizo, 12 kg.",
    "source": "api",
    "created_by": { "type": "api" },
    "cancelled_at": null,
    "cancellation_reason": null,
    "created_at": "2026-11-26T16:40:00.000Z",
    "updated_at": "2026-11-26T16:40:00.000Z"
  }
}
```

* `number`: correlative of the booking, shared with the business's appointments.
* `check_in`, `check_out`, `nights` and the times are computed from `start` and `end` in `time_zone`; nothing else is stored.
* `price`: the whole booking. `balance` is `price` minus `amount_paid`.
* `contact`: the public API never returns the customer's phone or email here.
* `status`: `awaiting_payment` (hold with a payment link), `booked`, `confirmed`, `completed`, `no_show` or `cancelled`.
* `payment_status`: `pending`, `partial`, `paid`, `refunded` or `cancelled`.

### 201 Created: block

The booking has the same fields, except that the night fields are replaced by the block's:

```json theme={"system"}
{
  "booking_unit": "block",
  "date": "2026-12-03",
  "start_time": "19:00",
  "end_time": "20:30",
  "duration_minutes": 90,
  "label": "jue 3 dic · 19:00 a 20:30"
}
```

### 400 Bad Request

```json theme={"system"}
{
  "error": {
    "code": "STAY_MIN_NIGHTS",
    "message": "La estadía mínima es de 2 noches",
    "details": { "min_nights": 2 }
  }
}
```

Other `400` codes:

```json theme={"system"}
{
  "STAY_INVALID_RANGE": "check_out is not after check_in, or the stay is longer than 92 nights",
  "STAY_MAX_NIGHTS": "more nights than the resource allows; details { max_nights }",
  "STAY_CLOSED_DAY": "no check-in or no check-out that day; details { date, side }",
  "STAY_OUTSIDE_WINDOW": "check_in_time or check_out_time outside the day's window; details { date, side, from, to }",
  "STAY_TOO_SOON": "the check-in is before the minimum notice",
  "STAY_TOO_FAR": "the check-in is further ahead than the business takes bookings",
  "BLOCK_SLOT_INVALID": "start_time is not a block the resource offers",
  "RESOURCE_DURATION_INVALID": "duration_minutes is not one the resource offers",
  "RESOURCE_BOOKING_UNIT_MISMATCH": "night fields on a block resource, or the other way around",
  "IDEMPOTENCY_KEY_REQUIRED": "missing or malformed Idempotency-Key"
}
```

### 404 Not Found

`RESOURCE_NOT_FOUND` or `BRANCH_NOT_FOUND`.

### 409 Conflict

```json theme={"system"}
{
  "error": {
    "code": "STAY_FULL",
    "message": "No queda cupo la noche del 2026-12-04",
    "details": { "date": "2026-12-04", "remaining": 0 }
  }
}
```

Other `409` codes:

```json theme={"system"}
{
  "RESOURCE_CONFLICT": "the block has no room left",
  "RESOURCE_PARTY_SIZE_INVALID": "the party does not fit one booking; details { min_party, max }",
  "RESOURCE_NOT_BOOKABLE": "the resource is inactive",
  "RESOURCE_PROFESSIONAL_BUSY": "the block resource belongs to a professional who already has an appointment, a time block or another booking at that time; details { professional_id, start, end }",
  "RESOURCE_BUSY": "another booking of the same resource was being written; details { retryable: true }"
}
```

On `STAY_FULL` or `RESOURCE_CONFLICT`, quote again and offer the new options. Do not retry the same dates. On `RESOURCE_PROFESSIONAL_BUSY`, don't retry that block: check [GET resources/availability](https://docs.keebai.com/dev/endpoints/scheduling-resource-availability.md) again for that day and offer another time or day. On `RESOURCE_BUSY`, retry the same request with the same `Idempotency-Key` after a short pause.

### 422 Unprocessable Entity

`ONLINE_PAYMENT_UNAVAILABLE`: the resource asks for a prepayment and the business can't take online payments right now. Nothing is booked.

### 502 Bad Gateway

`PAYMENT_LINK_FAILED`: the resource asks for a prepayment and the payment link could not be created. Keebai cancels the booking it had just made, so its nights are free again. Try again later.

### 503 Service Unavailable

`RESOURCE_LOCK_UNAVAILABLE` with `retryable: true`: Keebai couldn't lock the resource to write the booking. Nothing is booked. Retry the same request with the same `Idempotency-Key` after a short pause.

### 401 Unauthorized · 403 Forbidden

Same semantics as the rest of the public API.


## OpenAPI

````yaml POST /v1/scheduling/booking/resource-bookings
openapi: 3.0.0
info:
  title: Keebai Public API
  description: Superficie pública REST autenticada con Personal Access Tokens (PAT).
  version: 1.0.0
  contact: {}
servers:
  - url: https://api.keebai.com
    description: Production
security: []
tags: []
paths:
  /v1/scheduling/booking/resource-bookings:
    post:
      tags:
        - scheduling-resource-bookings
      summary: 'Book a resource: a stay on a night resource or a block'
      description: >-
        Send check_in/check_out for a night resource, or date/start_time for a
        block resource. A resource with a prepayment leaves the booking
        `awaiting_payment` with a payment link.
      operationId: PublicResourceBookingsController_create
      parameters:
        - name: idempotency-key
          required: true
          in: header
          schema:
            type: string
        - name: Idempotency-Key
          in: header
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicResourceBookingCreateDto'
      responses:
        '201':
          description: ''
      security:
        - PAT: []
components:
  schemas:
    PublicResourceBookingCreateDto:
      type: object
      properties:
        branch_id:
          type: string
          nullable: true
          description: Defaults to the resource branch.
        resource_id:
          type: string
        check_in:
          type: string
          example: '2026-12-03'
          description: Night only.
        check_out:
          type: string
          example: '2026-12-05'
          description: Night only.
        check_in_time:
          type: string
          nullable: true
          example: '11:00'
          description: Night only. Defaults to the opening of the check-in window.
        check_out_time:
          type: string
          nullable: true
          description: Night only. Defaults to the closing of the check-out window.
        date:
          type: string
          example: '2026-12-03'
          description: Block only.
        start_time:
          type: string
          example: '19:00'
          description: Block only.
        duration_minutes:
          type: number
          minimum: 15
          description: Block only.
        party_size:
          type: number
          minimum: 1
          default: 1
        customer:
          $ref: '#/components/schemas/PublicResourceBookingCustomerDto'
        notes:
          type: string
          nullable: true
      required:
        - resource_id
        - customer
    PublicResourceBookingCustomerDto:
      type: object
      properties:
        name:
          type: string
        last_name:
          type: string
          nullable: true
        phone:
          type: string
          example: '+56912345678'
        email:
          type: string
          nullable: true
        customer_id:
          type: string
          nullable: true
          description: CRM customer id, when you already have it.
      required:
        - name
        - phone
  securitySchemes:
    PAT:
      scheme: bearer
      bearerFormat: kbai_pk_<hex>
      type: http
      description: >-
        Personal Access Token con prefijo `kbai_pk_`. Generar desde el portal
        con permiso `developer.manage_tokens`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.