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

> Update a transport route and replace all its sections

# Update Transport Route

Update an existing transport route's metadata and sections. When `sections` is provided it **completely replaces** all existing sections — partial section patches are not supported. After a successful update, emissions are recalculated asynchronously and the route status is reset to `pending`.

<Warning>
  Sending `sections` deletes all existing sections and creates new ones. Any previously calculated distances and emissions for those sections are discarded and recalculated from scratch.
</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>

### Path Parameters

<ParamField path="transport_route_id" type="string" required>
  The unique identifier (UUID) of the transport route to update

  **Example:** `010ed3b6-b513-40f3-b9fe-0f0a338d9274`
</ParamField>

### Body

<ParamField body="name" type="string">
  Optional route name
</ParamField>

<ParamField body="transport_date" type="string">
  Date of transport in `YYYY-MM-DD` format

  **Example:** `2024-06-15`
</ParamField>

<ParamField body="quantity_transported" type="number">
  Amount transported. Must be greater than 0, max 10 digits with 3 decimal places

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

<ParamField body="supplier" type="string">
  Optional supplier name

  **Example:** `LogiTrans S.A.`
</ParamField>

<ParamField body="transport_frequency" type="string">
  Recurrence of this route. One of: `once`, `weekly`, `monthly`
</ParamField>

<ParamField body="unit_id" type="string">
  UUID of the measurement unit for `quantity_transported`

  **Example:** `61743a63-ff70-459c-9567-5eee8f7dfd5c`
</ParamField>

<ParamField body="sections" type="array" required>
  List of transport sections (legs). Must contain at least 1 item. **Replaces all existing sections.**

  <Expandable title="section fields">
    <ParamField body="sections[].transport_type" type="string" required>
      Mode of transport: `road`, `air`, `maritime`, `rail`, `do_not_know`
    </ParamField>

    <ParamField body="sections[].travel_method" type="string">
      Sub-type for road segments: `car`, `truck`, `motorbike`, `bicycle`, `electric_kick_scooter`
    </ParamField>

    <ParamField body="sections[].electric" type="boolean" required>
      Whether the vehicle is electric
    </ParamField>

    <ParamField body="sections[].refrigerated" type="boolean" required>
      Whether the cargo is refrigerated
    </ParamField>

    <ParamField body="sections[].distance_manual" type="boolean" required>
      Whether the distance is manually provided via `kms_manual`. Set to `true` when providing `kms_manual`, or `false` when using origin/destination geocoding.
    </ParamField>

    <ParamField body="sections[].detail" type="string">
      Additional detail for emission factor selection. Distance bands: `distance:ge:4000`, `distance:ge:1500`, `distance:ge:800`, `distance:lt:800`. Weight classes: `weight:ge:32000`, `weight:ge:16000`, `weight:ge:7500`, `weight:ge:3500`
    </ParamField>

    <ParamField body="sections[].origin" type="string">
      Origin location address used for automatic distance calculation

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

    <ParamField body="sections[].destination" type="string">
      Destination location address used for automatic distance calculation

      **Example:** `Latakia, Syria`
    </ParamField>

    <ParamField body="sections[].kms_manual" type="number">
      Distance override in kilometers. Skips automatic distance calculation when set. Must be greater than 0, max 7 digits with 2 decimal places

      **Example:** `4626.00`
    </ParamField>
  </Expandable>
</ParamField>

## Response

Returns the updated `TransportRouteSch` object with status `201 Created`.

<ResponseField name="id" type="string">
  Unique identifier (UUID)
</ResponseField>

<ResponseField name="name" type="string | null">
  Optional route name
</ResponseField>

<ResponseField name="transport_date" type="date">
  Date of transport (YYYY-MM-DD). `null` if not set
</ResponseField>

<ResponseField name="quantity_transported" type="number">
  Amount transported (max 10 digits, 3 decimal places)
</ResponseField>

<ResponseField name="supplier" type="string | null">
  Optional supplier name
</ResponseField>

<ResponseField name="transport_direction" type="string">
  `downstream` or `upstream`
</ResponseField>

<ResponseField name="transport_frequency" type="string">
  Recurrence: `once`, `weekly`, `monthly`
</ResponseField>

<ResponseField name="unit" type="object">
  Measurement unit for the quantity transported

  <Expandable title="unit fields">
    <ResponseField name="unit.id" type="string">UUID of the unit</ResponseField>
    <ResponseField name="unit.name" type="string">Unit name, e.g. `kilogram_(kg)`, `metric_tonne_(t)`</ResponseField>
    <ResponseField name="unit.type" type="string">Unit type, e.g. `solid`, `liquid`</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="status" type="string">
  Route status: `pending` immediately after update (recalculation in progress), `active` once complete, `error` if calculation failed
</ResponseField>

<ResponseField name="co2e" type="number | null">
  Total CO2-equivalent emissions in kg. `null` while recalculation is in progress
</ResponseField>

<ResponseField name="emissions" type="array">
  Route-level emissions summary: `[{"value": 245.67, "gas": "co2e", "unit_name": "kgCO2e"}]`
</ResponseField>

<ResponseField name="sections" type="array">
  Newly created sections. Emissions fields will be `null` until asynchronous calculation completes. See [Get Transport Route](/api-reference/transport/get) for the full section schema
</ResponseField>

<ResponseField name="file_id" type="string | null">
  ID of the file if this route was created via bulk upload
</ResponseField>

<ResponseField name="created_at" type="datetime">
  ISO 8601 creation timestamp
</ResponseField>

<ResponseField name="updated_at" type="datetime | null">
  ISO 8601 last-update timestamp
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X PUT "https://api.dcycle.io/v1/transports/010ed3b6-b513-40f3-b9fe-0f0a338d9274" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Madrid to Syria Shipment (revised)",
      "transport_date": "2024-07-01",
      "quantity_transported": 2500.000,
      "supplier": "LogiTrans S.A.",
      "transport_frequency": "once",
      "unit_id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
      "sections": [
        {
          "transport_type": "road",
          "travel_method": "truck",
          "electric": false,
          "refrigerated": false,
          "distance_manual": false,
          "origin": "Madrid, Spain",
          "destination": "Barcelona Port, Spain"
        },
        {
          "transport_type": "maritime",
          "electric": false,
          "refrigerated": false,
          "distance_manual": false,
          "origin": "Barcelona Port, Spain",
          "destination": "Latakia Port, Syria"
        }
      ]
    }'
  ```

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

  route_id = "010ed3b6-b513-40f3-b9fe-0f0a338d9274"

  response = requests.put(
      f"https://api.dcycle.io/v1/transports/{route_id}",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
      json={
          "name": "Madrid to Syria Shipment (revised)",
          "transport_date": "2024-07-01",
          "quantity_transported": 2500.000,
          "supplier": "LogiTrans S.A.",
          "transport_frequency": "once",
          "unit_id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
          "sections": [
              {
                  "transport_type": "road",
                  "travel_method": "truck",
                  "electric": False,
                  "refrigerated": False,
                  "distance_manual": False,
                  "origin": "Madrid, Spain",
                  "destination": "Barcelona Port, Spain",
              },
              {
                  "transport_type": "maritime",
                  "electric": False,
                  "refrigerated": False,
                  "distance_manual": False,
                  "origin": "Barcelona Port, Spain",
                  "destination": "Latakia Port, Syria",
              },
          ],
      },
  )

  route = response.json()
  print(f"Updated route: {route['id']}, status: {route['status']}")
  print(f"Sections replaced: {len(route['sections'])}")
  ```

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

  const routeId = '010ed3b6-b513-40f3-b9fe-0f0a338d9274';

  axios.put(
    `https://api.dcycle.io/v1/transports/${routeId}`,
    {
      name: 'Madrid to Syria Shipment (revised)',
      transport_date: '2024-07-01',
      quantity_transported: 2500.0,
      supplier: 'LogiTrans S.A.',
      transport_frequency: 'once',
      unit_id: '61743a63-ff70-459c-9567-5eee8f7dfd5c',
      sections: [
        {
          transport_type: 'road',
          travel_method: 'truck',
          electric: false,
          refrigerated: false,
          distance_manual: false,
          origin: 'Madrid, Spain',
          destination: 'Barcelona Port, Spain',
        },
        {
          transport_type: 'maritime',
          electric: false,
          refrigerated: false,
          distance_manual: false,
          origin: 'Barcelona Port, Spain',
          destination: 'Latakia Port, Syria',
        },
      ],
    },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
      },
    }
  )
  .then(({ data: route }) => {
    console.log(`Updated route: ${route.id}, status: ${route.status}`);
    console.log(`Sections replaced: ${route.sections.length}`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "010ed3b6-b513-40f3-b9fe-0f0a338d9274",
  "name": "Madrid to Syria Shipment (revised)",
  "transport_date": "2024-07-01",
  "quantity_transported": 2500.0,
  "supplier": "LogiTrans S.A.",
  "transport_direction": "downstream",
  "transport_frequency": "once",
  "unit": {
    "id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
    "name": "kilogram_(kg)",
    "type": "solid"
  },
  "status": "pending",
  "co2e": null,
  "emissions": null,
  "file_id": null,
  "sections": [
    {
      "id": "7a1b2c3d-0000-0000-0000-000000000001",
      "part": 1,
      "transport_type": "road",
      "travel_method": "truck",
      "electric": false,
      "refrigerated": false,
      "detail": null,
      "origin": "Madrid, Spain",
      "destination": "Barcelona Port, Spain",
      "kms": null,
      "kms_manual": null,
      "distance_manual": false,
      "kms_source": null,
      "status": "pending",
      "step": null,
      "error_messages": null,
      "emissions": null,
      "created_at": "2024-07-01T10:00:00Z",
      "updated_at": "2024-07-01T10:00:00Z"
    },
    {
      "id": "7a1b2c3d-0000-0000-0000-000000000002",
      "part": 2,
      "transport_type": "maritime",
      "travel_method": null,
      "electric": false,
      "refrigerated": false,
      "detail": null,
      "origin": "Barcelona Port, Spain",
      "destination": "Latakia Port, Syria",
      "kms": null,
      "kms_manual": null,
      "distance_manual": false,
      "kms_source": null,
      "status": "pending",
      "step": null,
      "error_messages": null,
      "emissions": null,
      "created_at": "2024-07-01T10:00:00Z",
      "updated_at": "2024-07-01T10:00:00Z"
    }
  ],
  "created_at": "2024-06-10T09:00:00Z",
  "updated_at": "2024-07-01T10:00:00Z"
}
```

<Note>
  The response status will be `pending` immediately after the update. Poll [Get Transport Route](/api-reference/transport/get) or use [Get Route Counts](/api-reference/transport/counts) to track when recalculation completes.
</Note>

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key / JWT token

```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:** Route ID does not exist or belongs to a different organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "TransportRoute not found", "code": "TRANSPORT_ROUTE_NOT_FOUND"}
```

### 422 Unprocessable Entity

**Cause:** Validation error — e.g. `sections` is empty, `quantity_transported` is zero or negative, or an enum value is invalid

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "sections"],
      "msg": "ensure this value has at least 1 items",
      "type": "value_error.list.min_items"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Transport Route" icon="route" href="/api-reference/transport/get">
    Retrieve a route by ID to check recalculation progress
  </Card>

  <Card title="Create Transport Route" icon="plus" href="/api-reference/transport/create">
    Create a new transport route with sections
  </Card>

  <Card title="Delete Transport Route" icon="trash" href="/api-reference/transport/delete">
    Remove a transport route permanently
  </Card>

  <Card title="Get Route Counts" icon="chart-bar" href="/api-reference/transport/counts">
    Monitor pending, active, and error counts
  </Card>

  <Card title="List Transport Routes" icon="list" href="/api-reference/transport/list">
    Retrieve all transport routes with filtering and pagination
  </Card>

  <Card title="Transport Overview" icon="book" href="/api-reference/transport/overview">
    Full data model and distance calculation reference
  </Card>
</CardGroup>
