> ## 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.

# Create Hotel Stay

> Create a hotel stay record and trigger asynchronous CO2e calculation

# Create Hotel Stay

Create a new hotel stay record. CO2e is calculated asynchronously using DEFRA emission factors based on the country and number of room-nights (rooms × nights).

## 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>

### Body Parameters

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

<ParamField body="check_out_date" type="string" required>
  Check-out date in ISO format (`YYYY-MM-DD`). Must be on or after `check_in_date`.
</ParamField>

<ParamField body="country" type="string" required>
  ISO-2 country code (e.g. `ES`, `GB`, `US`). Must be a country with available emission factors — see [Available Countries](/api-reference/hotel-stays/available-countries).
</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" default="1">
  Number of booked rooms (1–10 000)
</ParamField>

## Response

Returns the created hotel stay with CO2e fields (HTTP 201). CO2e may be `null` initially — it is calculated asynchronously.

<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: `api`, `csv`, or `manual`
</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. `null` until async calculation completes.
</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 POST "https://api.dcycle.io/v1/hotel-stays" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "check_in_date": "2025-03-10",
      "check_out_date": "2025-03-13",
      "country": "ES",
      "hotel_name": "Hotel Madrid Centro",
      "name": "Spring conference",
      "rooms": 1
    }'
  ```

  ```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",
  }

  response = requests.post(
      "https://api.dcycle.io/v1/hotel-stays",
      headers=headers,
      json={
          "check_in_date": "2025-03-10",
          "check_out_date": "2025-03-13",
          "country": "ES",
          "hotel_name": "Hotel Madrid Centro",
          "name": "Spring conference",
          "rooms": 1,
      },
  )

  stay = response.json()
  print(f"Created: {stay['id']} — {stay['check_in_date']} to {stay['check_out_date']}")
  ```

  ```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',
  };

  axios.post('https://api.dcycle.io/v1/hotel-stays', {
    check_in_date: '2025-03-10',
    check_out_date: '2025-03-13',
    country: 'ES',
    hotel_name: 'Hotel Madrid Centro',
    name: 'Spring conference',
    rooms: 1,
  }, { headers })
  .then(response => {
    console.log(`Created: ${response.data.id}`);
  });
  ```
</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-13",
  "country": "ES",
  "address": null,
  "hotel_name": "Hotel Madrid Centro",
  "rooms": 1,
  "status": "active",
  "source": "api",
  "file_id": null,
  "file_name": null,
  "co2e": null,
  "created_at": "2025-03-01T12:00:00Z",
  "updated_at": null,
  "uploaded_by": null,
  "location_geocode": null
}
```

<Note>
  `co2e` is `null` immediately after creation — it is calculated asynchronously and populated within a few seconds.
</Note>

## 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

```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="Available Countries" icon="globe" href="/api-reference/hotel-stays/available-countries">
    Check which countries have emission factors
  </Card>

  <Card title="List Hotel Stays" icon="list" href="/api-reference/hotel-stays/list">
    Browse all hotel stay records
  </Card>
</CardGroup>
