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

# Consumptions CSV Import

> Generate a presigned URL for bulk vehicle consumption import via CSV

# Consumptions CSV Import

Generate a presigned S3 upload URL for bulk importing vehicle consumption records via CSV file. After uploading the CSV to the returned URL, the system processes the file asynchronously and creates the consumption records.

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

<ParamField body="file_name" type="string" required>
  Name of the CSV file to upload (must end in `.csv`)

  **Example:** `fleet-fuel-q1-2025.csv`
</ParamField>

## Response

<ResponseField name="upload_url" type="string">
  Presigned S3 URL to upload the CSV file via PUT request
</ResponseField>

<ResponseField name="file_name" type="string">
  The file name as stored
</ResponseField>

<ResponseField name="file_id" type="string">
  UUID of the created file record for tracking
</ResponseField>

<ResponseField name="destination_file_key" type="string">
  S3 key where the file will be stored
</ResponseField>

<ResponseField name="message" type="string">
  Confirmation message
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  # Step 1: Get presigned upload URL
  RESPONSE=$(curl -s -X POST "https://api.dcycle.io/v1/vehicle_consumptions/bulk/csv" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{"file_name": "fleet-fuel-q1-2025.csv"}')

  UPLOAD_URL=$(echo $RESPONSE | jq -r '.upload_url')

  # Step 2: Upload the CSV to the presigned URL
  curl -X PUT "$UPLOAD_URL" \
    -H "Content-Type: text/csv" \
    --data-binary @fleet-fuel-q1-2025.csv
  ```

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

  headers = {
      "x-api-key": os.getenv("DCYCLE_API_KEY"),
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "Content-Type": "application/json",
  }

  # Step 1: Get presigned upload URL
  response = requests.post(
      "https://api.dcycle.io/v1/vehicle_consumptions/bulk/csv",
      headers=headers,
      json={"file_name": "fleet-fuel-q1-2025.csv"},
  )

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

  # Step 2: Upload the CSV
  with open("fleet-fuel-q1-2025.csv", "rb") as f:
      requests.put(upload_url, data=f, headers={"Content-Type": "text/csv"})

  print("Upload complete — processing will begin shortly")
  ```

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

  const headers = {
    'x-api-key': process.env.DCYCLE_API_KEY,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'Content-Type': 'application/json',
  };

  // Step 1: Get presigned upload URL
  const { data } = await axios.post(
    'https://api.dcycle.io/v1/vehicle_consumptions/bulk/csv',
    { file_name: 'fleet-fuel-q1-2025.csv' },
    { headers },
  );

  console.log(`File ID: ${data.file_id}`);

  // Step 2: Upload the CSV
  const csvData = fs.readFileSync('fleet-fuel-q1-2025.csv');
  await axios.put(data.upload_url, csvData, {
    headers: { 'Content-Type': 'text/csv' },
  });

  console.log('Upload complete — processing will begin shortly');
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "upload_url": "https://s3.eu-west-1.amazonaws.com/dcycle-uploads/...",
  "file_name": "fleet-fuel-q1-2025.csv",
  "file_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "destination_file_key": "organizations/org-uuid/vehicle-consumptions/a1b2c3d4.csv",
  "message": "Upload URL generated successfully"
}
```

## 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:** Invalid or missing file name in the request body

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "file_name"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Consumptions" icon="list" href="/api-reference/vehicles/consumptions">
    Browse imported consumption records
  </Card>

  <Card title="Delete by File" icon="trash" href="/api-reference/vehicles/consumptions-delete-by-file">
    Delete all consumptions from a specific import
  </Card>
</CardGroup>
