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

# Update Hotel Stay

> Update a hotel stay record (partial update) and trigger CO2e recalculation

# Update Hotel Stay

Update a hotel stay record with a partial update — only the fields you send are changed. CO2e is recalculated asynchronously if dates, country, or rooms change.

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### Path Parameters

<ParamField path="hotel_stay_id" type="string" required>
  UUID of the hotel stay to update
</ParamField>

### Body Parameters

All fields are optional — only send the ones you want to change.

<ParamField body="check_in_date" type="string">
  Check-in date in ISO format (`YYYY-MM-DD`)
</ParamField>

<ParamField body="check_out_date" type="string">
  Check-out date in ISO format (`YYYY-MM-DD`). When both dates are sent, check-out must be on or after check-in.
</ParamField>

<ParamField body="country" type="string">
  ISO-2 country code (e.g. `ES`, `GB`, `US`)
</ParamField>

<ParamField body="name" type="string">
  Label for the trip or traveler (max 255 characters)
</ParamField>

<ParamField body="hotel_name" type="string">
  Name of the hotel (max 255 characters)
</ParamField>

<ParamField body="address" type="string">
  Plain-text address for geocoding (max 500 characters)
</ParamField>

<ParamField body="rooms" type="integer">
  Number of booked rooms (1–10 000)
</ParamField>

<ParamField body="status" type="string">
  Record status. Values: `active`, `deleted`
</ParamField>

## Response

Returns the updated hotel stay with current CO2e (HTTP 200).

<ResponseField name="id" type="string">
  Hotel stay UUID
</ResponseField>

<ResponseField name="organization_id" type="string">
  UUID of the owning organization
</ResponseField>

<ResponseField name="name" type="string | null">
  Trip or traveler label
</ResponseField>

<ResponseField name="check_in_date" type="string">
  Check-in date (YYYY-MM-DD)
</ResponseField>

<ResponseField name="check_out_date" type="string">
  Check-out date (YYYY-MM-DD)
</ResponseField>

<ResponseField name="country" type="string">
  ISO-2 country code
</ResponseField>

<ResponseField name="address" type="string | null">
  Plain-text address
</ResponseField>

<ResponseField name="hotel_name" type="string | null">
  Hotel name
</ResponseField>

<ResponseField name="rooms" type="integer">
  Number of booked rooms
</ResponseField>

<ResponseField name="status" type="string">
  Record status: `active`, `pending`, or `deleted`
</ResponseField>

<ResponseField name="source" type="string">
  How the record was created: `manual`, `api`, `file_upload`
</ResponseField>

<ResponseField name="file_id" type="string | null">
  UUID of the source file, if created from a file upload
</ResponseField>

<ResponseField name="file_name" type="string | null">
  Name of the source file, if created from a file upload
</ResponseField>

<ResponseField name="co2e" type="number | null">
  Calculated CO2e emissions in tCO2e. May change after recalculation.
</ResponseField>

<ResponseField name="uploaded_by" type="string | null">
  UUID of the user who created the record
</ResponseField>

<ResponseField name="location_geocode" type="object | null">
  Geocoded location data resolved from the address

  | Field               | Type   | Description            |
  | ------------------- | ------ | ---------------------- |
  | `country_code`      | string | ISO-2 country code     |
  | `place_id`          | string | Place identifier       |
  | `address_formatted` | string | Full formatted address |
  | `latitude`          | number | Latitude coordinate    |
  | `longitude`         | number | Longitude coordinate   |
</ResponseField>

<ResponseField name="created_at" type="datetime">
  Creation timestamp
</ResponseField>

<ResponseField name="updated_at" type="datetime | null">
  Last update timestamp
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X PATCH "https://api.dcycle.io/v1/hotel-stays/${HOTEL_STAY_ID}" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "check_out_date": "2025-03-15",
      "rooms": 2
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  headers = {
      "x-api-key": os.getenv("DCYCLE_API_KEY"),
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "Content-Type": "application/json",
  }

  hotel_stay_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"

  response = requests.patch(
      f"https://api.dcycle.io/v1/hotel-stays/{hotel_stay_id}",
      headers=headers,
      json={"check_out_date": "2025-03-15", "rooms": 2},
  )

  stay = response.json()
  print(f"Updated: {stay['check_in_date']} to {stay['check_out_date']}, {stay['rooms']} rooms")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const headers = {
    'x-api-key': process.env.DCYCLE_API_KEY,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'Content-Type': 'application/json',
  };

  const hotelStayId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';

  axios.patch(`https://api.dcycle.io/v1/hotel-stays/${hotelStayId}`, {
    check_out_date: '2025-03-15',
    rooms: 2,
  }, { headers })
  .then(response => {
    const s = response.data;
    console.log(`Updated: ${s.check_in_date} to ${s.check_out_date}, ${s.rooms} rooms`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "organization_id": "a8315ef3-dd50-43f8-b7ce-d839e68d51fa",
  "name": "Spring conference",
  "check_in_date": "2025-03-10",
  "check_out_date": "2025-03-15",
  "country": "ES",
  "address": "Calle Gran Vía 28, Madrid",
  "hotel_name": "Hotel Madrid Centro",
  "rooms": 2,
  "status": "active",
  "source": "api",
  "file_id": null,
  "file_name": null,
  "co2e": 0.312,
  "created_at": "2025-03-01T12:00:00Z",
  "updated_at": "2025-03-02T09:30:00Z",
  "uploaded_by": null,
  "location_geocode": {
    "country_code": "ES",
    "place_id": "ChIJ_ynhfqgoQg0RJhAYCAE8uFk",
    "address_formatted": "Calle Gran Vía, 28, 28013 Madrid, Spain",
    "latitude": 40.4203,
    "longitude": -3.7065
  }
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 422 Validation Error

**Cause:** Check-out date is before check-in date (when both are provided)

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "check_out_date"],
      "msg": "check_out_date must be on or after check_in_date",
      "type": "value_error"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Hotel Stay" icon="magnifying-glass" href="/api-reference/hotel-stays/get">
    View hotel stay details
  </Card>

  <Card title="Impact Calculation" icon="calculator" href="/api-reference/hotel-stays/impact-calculation">
    View the CO2e calculation breakdown
  </Card>
</CardGroup>
