Skip to main content
PATCH
https://api.dcycle.io
/
v1
/
business-travels
/
{business_travel_id}
Update Business Travel
const options = {
  method: 'PATCH',
  headers: {
    Authorization: '<authorization>',
    'x-organization-id': '<x-organization-id>',
    'Content-Type': '<content-type>'
  },
  body: JSON.stringify({
    travel_date: '<string>',
    transport_type: '<string>',
    distance_km: 123,
    origin: '<string>',
    destination: '<string>',
    travel_number: 123,
    round_trip: true,
    vehicle_size: '<string>',
    fuel_type: '<string>',
    flight_type: '<string>',
    cabin_class: '<string>'
  })
};

fetch('https://api.dcycle.io/v1/business-travels/{business_travel_id}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

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.

Request

Headers

Authorization
string
required
Bearer token for authenticationExample: Bearer sk_live_1234567890abcdef
x-organization-id
string
required
Your organization UUIDExample: a8315ef3-dd50-43f8-b7ce-d839e68d51fa
Content-Type
string
required
Must be application/json

Path Parameters

business_travel_id
string
required
The unique identifier (UUID) of the business travel recordExample: 550e8400-e29b-41d4-a716-446655440000

Body Parameters

All fields are optional. Only include the fields you want to update.
travel_date
date
Date of the business travelFormat: YYYY-MM-DD
transport_type
string
Mode of transportAvailable values: car, metro, train, trolleybus, bus, motorbike, aircraft, ferry
distance_km
number
Distance traveled in kilometersConstraints: Must be positive
origin
string
Starting location address
destination
string
Ending location address
travel_number
integer
Number of travelersConstraints: 1 to 1000
round_trip
boolean
Whether this is a round trip
vehicle_size
string
Vehicle size (for car or motorbike)Available values: small, medium, large, average
fuel_type
string
Fuel type (for car or motorbike)Available values: petrol, diesel, cng, lpg, unknown, plug_in_hybrid_electric, battery_electric
flight_type
string
Flight type (for aircraft)Available values: domestic, short_haul_international, long_haul_international
cabin_class
string
Cabin class (for aircraft)Available values: economy, premium_economy, business, first, average

Response

Returns the updated business travel object.

Example

curl -X PATCH "https://api.dcycle.io/v1/business-travels/550e8400-e29b-41d4-a716-446655440000" \
  -H "Authorization: Bearer ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d '{
    "travel_number": 3,
    "round_trip": true
  }'

Successful Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "travel_date": "2024-12-01",
  "transport_type": "train",
  "distance_km": 621.5,
  "origin": "Madrid, Spain",
  "destination": "Barcelona, Spain",
  "travel_number": 3,
  "round_trip": true,
  "vehicle_size": null,
  "fuel_type": null,
  "flight_type": null,
  "cabin_class": null,
  "status": "pending",
  "co2e": 24.86,
  "created_at": "2024-12-01T10:30:00Z",
  "updated_at": "2024-12-01T14:45:00Z"
}
When updating fields that affect emissions (distance, transport type, travel number, round trip), the co2e value will be recalculated asynchronously. The status may temporarily change to pending.

Common Errors

401 Unauthorized

Cause: Missing or invalid API key
{
  "detail": "Invalid API key",
  "code": "INVALID_API_KEY"
}

404 Not Found

Cause: Business travel not found or doesn’t belong to your organization
{
  "detail": "BusinessTravel with id=550e8400-e29b-41d4-a716-446655440000 not found",
  "code": "BUSINESS_TRAVEL_NOT_FOUND"
}

422 Validation Error

Cause: Invalid field values
{
  "detail": [
    {
      "loc": ["body", "travel_number"],
      "msg": "ensure this value is less than or equal to 1000",
      "type": "value_error.number.not_le"
    }
  ]
}

Use Cases

Update Flight Class

Change the cabin class for an existing flight:
response = requests.patch(
    f"https://api.dcycle.io/v1/business-travels/{travel_id}",
    headers=headers,
    json={"cabin_class": "business"}
)
# Emissions will be recalculated for business class

Change Route with Distance Recalculation

Update origin and destination to recalculate distance:
response = requests.patch(
    f"https://api.dcycle.io/v1/business-travels/{travel_id}",
    headers=headers,
    json={
        "origin": "Paris, France",
        "destination": "Berlin, Germany"
    }
)
# Distance will be recalculated automatically

Correct Number of Travelers

response = requests.patch(
    f"https://api.dcycle.io/v1/business-travels/{travel_id}",
    headers=headers,
    json={"travel_number": 5}
)