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

> Create a new business travel record for emissions tracking

# Create Business Travel

Create a new business travel record in your organization. The system will automatically calculate CO2e emissions based on the transport type and distance.

<Note>
  **Distance Options**: You can provide either `distance_km` directly OR provide `origin` and `destination` addresses to have the distance calculated automatically.
</Note>

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

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`
</ParamField>

### Body Parameters

<ParamField body="transport_type" type="string" required>
  Mode of transport

  **Available values:** `car`, `metro`, `train`, `trolleybus`, `bus`, `motorbike`, `aircraft`, `ferry`
</ParamField>

<ParamField body="start_date" type="date" required>
  Start date of the business travel

  **Format:** `YYYY-MM-DD`

  **Example:** `"2024-12-01"`
</ParamField>

<ParamField body="end_date" type="date" required>
  End date of the business travel. Must be on or after `start_date`

  **Format:** `YYYY-MM-DD`

  **Example:** `"2024-12-01"`
</ParamField>

<ParamField body="distance_km" type="number">
  Distance traveled in kilometers (required if `origin`/`destination` not provided)

  **Constraints:** Must be greater than 0

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

<ParamField body="origin" type="string">
  Starting location address (required if `distance_km` not provided)

  **Constraints:** Max 500 characters

  **Example:** `"Madrid, Spain"`
</ParamField>

<ParamField body="destination" type="string">
  Ending location address (required if `distance_km` not provided). Cannot be the same as `origin` unless `distance_km` is also provided.

  **Constraints:** Max 500 characters

  **Example:** `"Barcelona, Spain"`
</ParamField>

<ParamField body="name" type="string">
  Optional label for this travel record

  **Constraints:** Max 255 characters

  **Example:** `"Q4 Sales Conference"`
</ParamField>

<ParamField body="email" type="string">
  Email of the traveler

  **Example:** `"j.garcia@example.com"`
</ParamField>

<ParamField body="travel_type" type="string" default="one_way">
  Whether this is a one-way or round trip

  **Available values:** `one_way`, `round`
</ParamField>

<ParamField body="travel_number" type="integer" default="1">
  Number of trips

  **Constraints:** 1 to 10,000 (further limited by date range — max 100 per day)

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

<ParamField body="passenger_number" type="integer" default="1">
  Number of passengers per trip

  **Constraints:** Must be at least 1

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

<ParamField body="vehicle_size" type="string">
  Vehicle size. **Required** when `transport_type` is `car`, not allowed for other types.

  **Available values:** `small`, `medium`, `large`
</ParamField>

<ParamField body="fuel_type" type="string">
  Fuel type. **Required** when `transport_type` is `car`, not allowed for other types.

  **Available values:** `diesel`, `petrol`, `natural_gas`, `lpg`, `electric`, `hybrid`, `not_fuel_based`, `do_not_know`
</ParamField>

<ParamField body="renewable_energy" type="string">
  Whether the vehicle uses renewable energy

  **Available values:** `yes`, `no`, `do_not_know`
</ParamField>

## Response

Returns the created business travel object with HTTP status **201 Created**.

<Note>
  The `co2e` value may initially be `0` with `status: "pending"`. Emissions are calculated asynchronously and the value will be updated shortly. Use the [Get Business Travel](/api-reference/business-travels/get) endpoint to check the updated value.
</Note>

<ResponseField name="id" type="string">
  Unique identifier (UUID) for the new record
</ResponseField>

<ResponseField name="organization_id" type="string">
  Organization UUID
</ResponseField>

<ResponseField name="name" type="string | null">
  Travel record label
</ResponseField>

<ResponseField name="email" type="string | null">
  Traveler email
</ResponseField>

<ResponseField name="transport_type" type="string">
  Mode of transport
</ResponseField>

<ResponseField name="start_date" type="date">
  Start date of travel
</ResponseField>

<ResponseField name="end_date" type="date">
  End date of travel
</ResponseField>

<ResponseField name="distance_km" type="number | null">
  Distance in km (calculated if origin/destination provided)
</ResponseField>

<ResponseField name="distance_source" type="string | null">
  How the distance was obtained: `manual` (provided directly), `geodesic` (great-circle for aircraft), or `google_maps` (other transport types with origin/destination)
</ResponseField>

<ResponseField name="origin" type="string | null">
  Starting location address
</ResponseField>

<ResponseField name="destination" type="string | null">
  Ending location address
</ResponseField>

<ResponseField name="origin_geocode" type="object | null">
  Geocoded origin location resolved from the origin 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="destination_geocode" type="object | null">
  Geocoded destination location (same structure as `origin_geocode`)
</ResponseField>

<ResponseField name="travel_type" type="string">
  Trip type: `one_way` or `round`
</ResponseField>

<ResponseField name="travel_number" type="integer">
  Number of trips
</ResponseField>

<ResponseField name="passenger_number" type="integer">
  Number of passengers per trip
</ResponseField>

<ResponseField name="vehicle_size" type="string | null">
  Vehicle size (car only)
</ResponseField>

<ResponseField name="fuel_type" type="string | null">
  Fuel type (car only)
</ResponseField>

<ResponseField name="renewable_energy" type="string | null">
  Renewable energy usage
</ResponseField>

<ResponseField name="status" type="string">
  Record status: `pending` immediately after creation, `active` once calculation completes, `error` if calculation failed
</ResponseField>

<ResponseField name="source" type="string">
  Record source: `api` for records created via this endpoint
</ResponseField>

<ResponseField name="co2e" type="number | null">
  Calculated CO2 equivalent emissions in kg. `null` or `0` while calculation is pending
</ResponseField>

<ResponseField name="file_id" type="string | null">
  File UUID if created via bulk upload (always `null` for API-created records)
</ResponseField>

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

<ResponseField name="uploaded_by" type="object | null">
  The authenticated user who created this record
</ResponseField>

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

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

## Example

### Train Travel with Direct Distance

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/business-travels" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "transport_type": "train",
      "start_date": "2024-12-01",
      "end_date": "2024-12-01",
      "distance_km": 621.5,
      "travel_number": 2,
      "travel_type": "one_way"
    }'
  ```

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

  response = requests.post(
      "https://api.dcycle.io/v1/business-travels",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
      json={
          "transport_type": "train",
          "start_date": "2024-12-01",
          "end_date": "2024-12-01",
          "distance_km": 621.5,
          "travel_number": 2,
          "travel_type": "one_way",
      },
  )

  travel = response.json()
  print(f"Created travel: {travel['id']}")
  print(f"Status: {travel['status']}")
  ```

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

  axios.post(
    'https://api.dcycle.io/v1/business-travels',
    {
      transport_type: 'train',
      start_date: '2024-12-01',
      end_date: '2024-12-01',
      distance_km: 621.5,
      travel_number: 2,
      travel_type: 'one_way',
    },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
      },
    }
  )
  .then(({ data: travel }) => {
    console.log(`Created travel: ${travel.id}`);
    console.log(`Status: ${travel.status}`);
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

### Flight with Origin/Destination

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/business-travels" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "transport_type": "aircraft",
      "start_date": "2024-12-05",
      "end_date": "2024-12-05",
      "origin": "Madrid, Spain",
      "destination": "London, UK",
      "travel_type": "round",
      "passenger_number": 1
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  response = requests.post(
      "https://api.dcycle.io/v1/business-travels",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
      json={
          "transport_type": "aircraft",
          "start_date": "2024-12-05",
          "end_date": "2024-12-05",
          "origin": "Madrid, Spain",
          "destination": "London, UK",
          "travel_type": "round",
          "passenger_number": 1,
      },
  )

  travel = response.json()
  print(f"Distance: {travel['distance_km']} km ({travel['distance_source']})")
  print(f"Status: {travel['status']}")
  ```
</CodeGroup>

### Car Travel with Vehicle Details

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/business-travels" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "transport_type": "car",
      "start_date": "2024-12-10",
      "end_date": "2024-12-10",
      "origin": "Madrid, Spain",
      "destination": "Valencia, Spain",
      "vehicle_size": "medium",
      "fuel_type": "diesel",
      "travel_number": 3
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  response = requests.post(
      "https://api.dcycle.io/v1/business-travels",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
      json={
          "transport_type": "car",
          "start_date": "2024-12-10",
          "end_date": "2024-12-10",
          "origin": "Madrid, Spain",
          "destination": "Valencia, Spain",
          "vehicle_size": "medium",
          "fuel_type": "diesel",
          "travel_number": 3,
      },
  )
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "organization_id": "a8315ef3-dd50-43f8-b7ce-d839e68d51fa",
  "name": null,
  "email": null,
  "transport_type": "train",
  "start_date": "2024-12-01",
  "end_date": "2024-12-01",
  "distance_km": 621.5,
  "distance_source": "manual",
  "origin": null,
  "destination": null,
  "origin_geocode": null,
  "destination_geocode": null,
  "travel_type": "one_way",
  "travel_number": 2,
  "passenger_number": 1,
  "vehicle_size": null,
  "fuel_type": null,
  "renewable_energy": null,
  "status": "pending",
  "source": "api",
  "co2e": 0,
  "file_id": null,
  "file_name": null,
  "uploaded_by": {
    "id": "user-123",
    "first_name": "Maria",
    "last_name": "García",
    "profile_img_url": null
  },
  "created_at": "2024-12-01T10:30:00Z",
  "updated_at": "2024-12-01T10:30:00Z"
}
```

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

**Cause:** Missing required fields — must provide either `distance_km` OR both `origin` and `destination`

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body"],
      "msg": "Either distance_km or origin+destination must be provided",
      "type": "value_error"
    }
  ]
}
```

**Cause:** Missing `vehicle_size` or `fuel_type` when `transport_type` is `car`

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body"],
      "msg": "vehicle_size is required for car transport",
      "type": "value_error"
    }
  ]
}
```

**Cause:** `end_date` is before `start_date`

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

**Cause:** Unknown field sent in request body (this endpoint rejects extra fields)

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "round_trip"],
      "msg": "extra fields not permitted",
      "type": "value_error.extra"
    }
  ]
}
```

## Validation Rules

1. **Distance Input**: Provide either `distance_km` OR both `origin` and `destination`
2. **Date Range**: `end_date` must be on or after `start_date`
3. **Travel Number**: 1 to 10,000, further limited to max 100 per day in the date range
4. **Car Transport**: `vehicle_size` and `fuel_type` are required when `transport_type` is `car`
5. **Vehicle Size Restriction**: `vehicle_size` is only allowed for `car` transport
6. **Extra Fields**: This endpoint rejects any fields not listed above (e.g. `flight_type`, `cabin_class`, `round_trip`)

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Business Travels" icon="list" href="/api-reference/business-travels/list">
    Retrieve all business travels
  </Card>

  <Card title="Get Business Travel" icon="magnifying-glass" href="/api-reference/business-travels/get">
    Get a specific business travel
  </Card>

  <Card title="Update Business Travel" icon="pencil" href="/api-reference/business-travels/update">
    Modify business travel details
  </Card>

  <Card title="Delete Business Travel" icon="trash" href="/api-reference/business-travels/delete">
    Remove a business travel record
  </Card>
</CardGroup>
