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

# Upload Transport File

> Upload a CSV, XLS, or XLSX file to bulk-create transport routes

# Upload Transport File

Upload a spreadsheet file containing transport routes. The file is processed asynchronously — rows are parsed, geocoded, and emission factors are resolved in the background after the upload returns.

<Note>
  For files larger than a few MB, use the [Presigned URL](/api-reference/transport/presigned-url) approach instead. It uploads the file directly to S3 without routing the bytes through the API server.
</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>

### Body (multipart/form-data)

<ParamField body="transport_direction" type="string" required>
  The GHG Protocol scope 3 direction of these transport routes.

  * `downstream` — transport paid by your organization after the sale (Category 9)
  * `upstream` — inbound transport paid by your organization (Category 4)
</ParamField>

<ParamField body="upload_file" type="file" required>
  The spreadsheet file to upload. Accepted formats: `.csv`, `.xls`, `.xlsx`.
</ParamField>

## Response

<ResponseField name="message" type="string">
  Human-readable confirmation message.

  **Example:** `"Transport route file uploaded"`
</ResponseField>

<ResponseField name="file_id" type="string">
  UUID that identifies this upload batch. Use it to filter routes via `GET /v1/transports?file_id=<file_id>` or to track processing progress.

  **Example:** `"b3d7c1e2-4a5f-48d9-b6e8-1234567890ab"`
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/transports/upload" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -F "transport_direction=downstream" \
    -F "upload_file=@transport_routes.xlsx"
  ```

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

  api_key = os.getenv("DCYCLE_API_KEY")
  org_id = os.getenv("DCYCLE_ORG_ID")

  headers = {
      "x-api-key": api_key,
      "x-organization-id": org_id,
  }

  with open("transport_routes.xlsx", "rb") as f:
      response = requests.post(
          "https://api.dcycle.io/v1/transports/upload",
          headers=headers,
          data={"transport_direction": "downstream"},
          files={"upload_file": ("transport_routes.xlsx", f, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")},
      )

  result = response.json()
  print(f"File ID: {result['file_id']}")
  print(f"Message: {result['message']}")
  ```

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

  const apiKey = process.env.DCYCLE_API_KEY;
  const orgId = process.env.DCYCLE_ORG_ID;

  const form = new FormData();
  form.append('transport_direction', 'downstream');
  form.append('upload_file', fs.createReadStream('transport_routes.xlsx'));

  axios.post('https://api.dcycle.io/v1/transports/upload', form, {
    headers: {
      'x-api-key': apiKey,
      'x-organization-id': orgId,
      ...form.getHeaders(),
    },
  })
  .then(response => {
    const result = response.data;
    console.log(`File ID: ${result.file_id}`);
    console.log(`Message: ${result.message}`);
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "message": "Transport route file uploaded",
  "file_id": "b3d7c1e2-4a5f-48d9-b6e8-1234567890ab"
}
```

## Asynchronous Processing

The endpoint returns immediately with status `201`. The actual processing happens in the background:

1. Rows are parsed from the uploaded file.
2. Origin and destination addresses are geocoded (Google Maps Distance Matrix API for road/rail, haversine for air, sea-distance tables for maritime).
3. Emission factors are resolved and CO2e values are calculated.

You can poll the processing status by listing routes filtered by the returned `file_id`:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://api.dcycle.io/v1/transports?file_id=b3d7c1e2-4a5f-48d9-b6e8-1234567890ab" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}"
```

Route statuses move through `pending` → `active` (success) or `error` as processing completes.

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key / Bearer token.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Invalid API key",
  "code": "INVALID_API_KEY"
}
```

### 422 Unprocessable Entity

**Cause:** `transport_direction` is missing or not one of the accepted values.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "transport_direction"],
      "msg": "value is not a valid enumeration member",
      "type": "type_error.enum"
    }
  ]
}
```

**Solution:** Set `transport_direction` to `downstream` or `upstream`.

### 400 Bad Request

**Cause:** Unsupported file format (not `.csv`, `.xls`, or `.xlsx`).

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Unsupported file format. Use CSV, XLS, or XLSX.",
  "code": "INVALID_FILE_FORMAT"
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Presigned URL Upload" icon="cloud-arrow-up" href="/api-reference/transport/presigned-url">
    Upload large files directly to S3 via a presigned URL
  </Card>

  <Card title="List Transport Routes" icon="list" href="/api-reference/transport/get">
    Retrieve transport routes, filter by file\_id to track batch processing
  </Card>

  <Card title="Transport Combinations" icon="shuffle" href="/api-reference/transport/combinations">
    Explore valid transport type and method combinations before creating routes
  </Card>

  <Card title="Transport Overview" icon="truck" href="/api-reference/transport/overview">
    Learn the full Transport API data model and workflow
  </Card>
</CardGroup>
