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

# Delete Vehicle Consumptions by File

> Delete all vehicle consumption records associated with a CSV upload file ID, across the entire holding

# Delete Vehicle Consumptions by File

Delete all vehicle consumption records that were created from a specific CSV bulk upload, identified by its `file_id`. This endpoint traverses the full holding hierarchy, removing matching records from the parent organization and all child organizations.

<Warning>
  **Irreversible Action**: This permanently deletes all consumption records linked to the given file. All associated CO₂e impact data will be removed across every organization in the holding.
</Warning>

<Note>
  **Holding-aware**: When a CSV is uploaded to a parent organization, consumption records may be created across multiple child organizations. This endpoint finds and deletes all of them in a single call.
</Note>

## Request

### Path Parameters

<ParamField path="file_id" type="uuid" required>
  The UUID of the file whose associated consumption records should be deleted. This is the `file_id` returned when the bulk CSV upload was processed.

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### 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. The deletion will include consumption records from this organization and all child organizations in the holding.

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

## Response

Returns `204 No Content` on success, even if no records matched the given `file_id`. No response body.

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X DELETE "https://api.dcycle.io/v1/vehicle_consumptions/by-file/a8315ef3-dd50-43f8-b7ce-d839e68d51fa" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}"
  ```

  ```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")
  file_id = "a8315ef3-dd50-43f8-b7ce-d839e68d51fa"

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

  response = requests.delete(
      f"https://api.dcycle.io/v1/vehicle_consumptions/by-file/{file_id}",
      headers=headers
  )

  if response.status_code == 204:
      print("Vehicle consumptions deleted successfully")
  else:
      print(f"Error: {response.status_code}")
  ```

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

  const apiKey = process.env.DCYCLE_API_KEY;
  const orgId = process.env.DCYCLE_ORG_ID;
  const fileId = 'a8315ef3-dd50-43f8-b7ce-d839e68d51fa';

  const headers = {
    'x-api-key': apiKey,
    'x-organization-id': orgId
  };

  axios.delete(
    `https://api.dcycle.io/v1/vehicle_consumptions/by-file/${fileId}`,
    { headers }
  )
  .then(response => {
    if (response.status === 204) {
      console.log('Vehicle consumptions deleted successfully');
    }
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

### Successful Response

```
HTTP/1.1 204 No Content
```

No response body is returned. If no records matched the `file_id`, the response is still `204`.

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

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

**Solution:** Verify your API key is valid and active. Get a new one from [Settings → API](https://app.dcycle.io/settings/api).

### 422 Validation Error

**Cause:** Malformed UUID in path parameter

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["path", "file_id"],
      "msg": "value is not a valid uuid",
      "type": "type_error.uuid"
    }
  ]
}
```

## Use Cases

### Undo a Bulk CSV Upload

When a user uploads a CSV file and realizes it contained errors, use this endpoint to remove all the records it created before re-uploading the corrected file:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def undo_csv_upload(file_id):
    """Remove all consumptions created by a bulk CSV upload"""
    response = requests.delete(
        f"https://api.dcycle.io/v1/vehicle_consumptions/by-file/{file_id}",
        headers=headers
    )

    if response.status_code == 204:
        print(f"All consumptions from file {file_id} removed")
        return True
    else:
        print(f"Failed: {response.status_code}")
        return False
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Vehicle Consumptions" icon="list" href="/api-reference/vehicles/consumptions">
    List all consumption records for a vehicle
  </Card>

  <Card title="Delete Vehicle Consumption" icon="trash" href="/api-reference/vehicles/consumptions-delete">
    Delete a single consumption record by ID
  </Card>

  <Card title="Bulk Delete Consumptions" icon="trash-can" href="/api-reference/vehicles/consumptions-bulk-delete">
    Delete multiple consumption records by their IDs
  </Card>

  <Card title="Bulk Delete by Filters" icon="filter" href="/api-reference/vehicles/consumptions-bulk-delete-by-filters">
    Delete consumptions matching filter criteria
  </Card>
</CardGroup>
