# Booking Update

## Update a Booking

Use this endpoint to modify an existing booking. You can change **dates**, **room**, and **notes**.\
Updates to dates or room will re-check availability and pricing rules.

#### Endpoint

```http
PATCH /api/v1/client/bookings/{bookingId}
```

#### Example `curl`

```bash
curl "/api/v1/client/bookings/e7b7f6bb-6c0c-4e2c-9b3e-9c6f2a1c0a77" \
  -X PATCH \
  -H "accept: application/json" \
  -H "content-type: application/json" \
  -H "origin: https://docs.hostelmate.co" \
  --data-raw '{
    "booking": {
      "dates": [
        { "date": "2025-12-19", "amount": 26000 },
        { "date": "2025-12-20", "amount": 26000 }
      ]
    },
  }'
```

> This is a **partial** update. Send only the fields you want to change.

***

#### Request Payload

**Top-level Fields**

<table><thead><tr><th width="104.3515625">Field</th><th width="92.70703125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>booking</code></td><td>object</td><td>Booking-level updates, such as new nightly dates/amounts.</td></tr><tr><td><code>room</code></td><td>string</td><td>Change to a different room or room type ID (UUID).</td></tr><tr><td><code>notes</code></td><td>string</td><td>Update internal notes for the booking.</td></tr></tbody></table>

**Booking Object (updatable)**

<table><thead><tr><th width="104.3515625">Field</th><th width="92.70703125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>dates</code></td><td>array</td><td>Replace the nightly pricing array. The server will recompute <em>total</em> as the sum of these amounts.</td></tr></tbody></table>

**Dates Item**

<table><thead><tr><th width="104.3515625">Field</th><th width="92.70703125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td>string</td><td>Night date (format: YYYY-MM-DD).</td></tr><tr><td><code>amount</code></td><td>integer</td><td>Nightly amount in **minor units** (e.g., 26000 represents 260.00).</td></tr></tbody></table>

***

#### Update Status or Notes (Recommended Action)

Use this dedicated endpoint to update specific booking flags.

```http
POST /api/v1/client/bookings/{bookingId}/update
```

**Payload**

```json
{
  "status": "paid",
  "notes": "Payment confirmed via wire transfer"
}
```

**Response (200 OK)**

```json
{
  "id": "e7b7f6bb-6c0c-4e2c-9b3e-9c6f2a1c0a77",
  "status": "paid",
  "total": 52000,
  "created": "2025-10-01T10:00:00Z",
  "updated": "2025-10-02T11:05:13Z",
  ...
}
```

***

#### Update a Booking (Partial PATCH)

Use this endpoint to modify dates or rooms. Availability and totals are revalidated; send only fields you want to change.

#### Endpoint

```http
PATCH /api/v1/client/bookings/{bookingId}
```

**Response (200 OK)**

```json
{
  "bookingId": "e7b7f6bb-6c0c-4e2c-9b3e-9c6f2a1c0a77",
  "status": "confirmed",
  "room": "92b6f8b8-6ea2-4e0e-9b7b-3e2f9b6a7c2d",
  "total": 52000,
  ...
}
```

#### Example `curl`

```bash
curl "/api/v1/client/bookings/e7b7f6bb-6c0c-4e2c-9b3e-9c6f2a1c0a77" \
  -X PATCH \
  -H "accept: application/json" \
  -H "content-type: application/json" \
  -H "origin: https://docs.hostelmate.co" \
  --data-raw '{
    "booking": {
      "dates": [
        { "date": "2025-12-19", "amount": 26000 },
        { "date": "2025-12-20", "amount": 26000 }
      ]
    },
  }'
```

> This is a **partial** update. Send only the fields you want to change.

***

#### Request Payload

**Top-level Fields**

<table><thead><tr><th width="104.3515625">Field</th><th width="92.70703125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>booking</code></td><td>object</td><td>Booking-level updates, such as new nightly dates/amounts.</td></tr><tr><td><code>room</code></td><td>string</td><td>Change to a different room or room type ID (UUID).</td></tr><tr><td><code>notes</code></td><td>string</td><td>Update internal notes for the booking.</td></tr></tbody></table>

**Booking Object (updatable)**

<table><thead><tr><th width="104.3515625">Field</th><th width="92.70703125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>dates</code></td><td>array</td><td>Replace the nightly pricing array. The server will recompute <em>total</em> as the sum of these amounts.</td></tr></tbody></table>

**Dates Item**

<table><thead><tr><th width="104.3515625">Field</th><th width="92.70703125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>date</code></td><td>string</td><td>Night date (format: YYYY-MM-DD).</td></tr><tr><td><code>amount</code></td><td>integer</td><td>Nightly amount in **minor units** (e.g., 26000 represents 260.00).</td></tr></tbody></table>

***

> **Note on Amounts**: All amount fields in the Booking API use **minor units** (integers). For example, to send `100.00`, use `10000`.

***

#### Response (200 OK)

```json
{
  "bookingId": "e7b7f6bb-6c0c-4e2c-9b3e-9c6f2a1c0a77",
  "status": "confirmed",
  "room": "7b9e2f12-34cd-4e89-bf45-4a18f5a8a1f0",
  "total": 52000,
  "dates": [
    { "date": "2025-12-19", "amount": 26000 },
    { "date": "2025-12-20", "amount": 26000 }
  ],
  "updated": "2025-10-02T11:05:13Z"
}
```

***

#### Validation Rules

* The request may include any subset of fields; missing fields are left unchanged.
* If `booking.dates` is provided:
  * It must contain at least one item.
  * `date` must be valid (YYYY-MM-DD).
  * `amount` must be a non-negative integer.
  * The server recomputes `total` from the provided dates.
* If `room` is provided, availability for the existing dates is re-validated.

***

#### Error Codes

<table><thead><tr><th width="104.3515625">HTTP</th><th width="92.70703125">Code</th><th>Description</th></tr></thead><tbody><tr><td>400</td><td><code>bad_request</code></td><td>Invalid field(s) or payload structure.</td></tr><tr><td>404</td><td><code>booking_not_found</code></td><td>No booking with the specified <code>bookingId</code>.</td></tr><tr><td>404</td><td><code>room_not_found</code></td><td>The specified <code>room</code> does not exist.</td></tr><tr><td>409</td><td><code>availability_conflict</code></td><td>New dates/room are not available.</td></tr><tr><td>422</td><td><code>pricing_mismatch</code></td><td><code>dates[].amount</code> do not comply with rate rules.</td></tr><tr><td>500</td><td><code>server_error</code></td><td>Unexpected error.</td></tr></tbody></table>
