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

> Update an existing business travel record

# Update Business Travel

Update an existing business travel record. Only provide the fields you want to change. Emissions will be recalculated automatically if relevant fields are modified.

<Warning>
  Even though all fields are individually optional, you must always provide either `distance_km` OR both `origin` and `destination` in every update request — the distance validation runs on every call.
</Warning>

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

### Path Parameters

<ParamField path="business_travel_id" type="string" required>
  The unique identifier (UUID) of the business travel record

  **Example:** `550e8400-e29b-41d4-a716-446655440000`
</ParamField>

### Body Parameters

All fields are optional. Only include the fields you want to update.

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

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

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

  **Format:** `YYYY-MM-DD`
</ParamField>

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

  **Format:** `YYYY-MM-DD`
</ParamField>

<ParamField body="distance_km" type="number">
  Distance traveled in kilometers

  **Constraints:** Must be greater than 0
</ParamField>

<ParamField body="origin" type="string">
  Starting location address

  **Constraints:** Max 500 characters

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

<ParamField body="destination" type="string">
  Ending location address. 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
</ParamField>

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

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

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

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

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

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

  **Constraints:** Must be at least 1
</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>

<ParamField body="status" type="string">
  Record status

  **Available values:** `active`, `pending`, `loading`, `completed`, `error`
</ParamField>

## Response

Returns the updated business travel object.

<ResponseField name="id" type="string">
  Unique identifier (UUID)
</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
</ResponseField>

<ResponseField name="distance_source" type="string | null">
  How the distance was obtained: `manual`, `geodesic`, or `google_maps`
</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`, `active`, `error`, `loading`, or `completed`
</ResponseField>

<ResponseField name="source" type="string">
  Record source: `api`, `manual`, `bulk_upload`, or `form`
</ResponseField>

<ResponseField name="co2e" type="number | null">
  Calculated CO2 equivalent emissions in kg
</ResponseField>

<ResponseField name="file_id" type="string | null">
  File UUID if created via bulk upload
</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 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

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X PATCH "https://api.dcycle.io/v1/business-travels/550e8400-e29b-41d4-a716-446655440000" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "travel_number": 3,
      "travel_type": "round",
      "origin": "Madrid, Spain",
      "destination": "Barcelona, Spain"
    }'
  ```

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

  travel_id = "550e8400-e29b-41d4-a716-446655440000"

  response = requests.patch(
      f"https://api.dcycle.io/v1/business-travels/{travel_id}",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
      json={
          "travel_number": 3,
          "travel_type": "round",
          "origin": "Madrid, Spain",
          "destination": "Barcelona, Spain",
      },
  )

  travel = response.json()
  print(f"Updated travel: {travel['id']}")
  print(f"New emissions: {travel['co2e']} kg CO2e")
  ```

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

  const travelId = '550e8400-e29b-41d4-a716-446655440000';

  axios.patch(
    `https://api.dcycle.io/v1/business-travels/${travelId}`,
    {
      travel_number: 3,
      travel_type: 'round',
      origin: 'Madrid, Spain',
      destination: 'Barcelona, Spain',
    },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
      },
    }
  )
  .then(({ data: travel }) => {
    console.log(`Updated travel: ${travel.id}`);
    console.log(`New emissions: ${travel.co2e} kg CO2e`);
  })
  .catch(error => console.error(error));
  ```
</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": "google_maps",
  "origin": "Madrid, Spain",
  "destination": "Barcelona, Spain",
  "origin_geocode": null,
  "destination_geocode": null,
  "travel_type": "round",
  "travel_number": 3,
  "passenger_number": 1,
  "vehicle_size": null,
  "fuel_type": null,
  "renewable_energy": null,
  "status": "pending",
  "source": "api",
  "co2e": 24.86,
  "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-01T14:45:00Z"
}
```

<Note>
  When updating fields that affect emissions (distance, transport type, travel number, travel type), the `co2e` value will be recalculated asynchronously. The status may temporarily change to `pending`.
</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"}
```

### 404 Not Found

**Cause:** Business travel not found or doesn't belong to your organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "BusinessTravel with id=550e8400-e29b-41d4-a716-446655440000 not found", "code": "BUSINESS_TRAVEL_NOT_FOUND"}
```

### 422 Unprocessable Entity

**Cause:** Missing distance — 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:** 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"
    }
  ]
}
```

## Use Cases

### Change Route with Distance Recalculation

Update origin and destination to recalculate distance:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
response = requests.patch(
    f"https://api.dcycle.io/v1/business-travels/{travel_id}",
    headers=headers,
    json={
        "origin": "Paris, France",
        "destination": "Berlin, Germany",
    },
)
```

### Switch to Round Trip

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
response = requests.patch(
    f"https://api.dcycle.io/v1/business-travels/{travel_id}",
    headers=headers,
    json={
        "travel_type": "round",
        "origin": "Madrid, Spain",
        "destination": "Barcelona, Spain",
    },
)
```

### Update Car Details

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
response = requests.patch(
    f"https://api.dcycle.io/v1/business-travels/{travel_id}",
    headers=headers,
    json={
        "vehicle_size": "large",
        "fuel_type": "hybrid",
        "distance_km": 350.0,
    },
)
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Business Travel" icon="magnifying-glass" href="/api-reference/business-travels/get">
    Get current business travel details
  </Card>

  <Card title="Create Business Travel" icon="plus" href="/api-reference/business-travels/create">
    Create a new business travel record
  </Card>

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

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