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

> Remove a vehicle from your organization's fleet

# Delete Vehicle

Permanently remove a vehicle from your organization's fleet. This action cannot be undone.

<Warning>
  **Irreversible Action**: Deleting a vehicle will remove all associated data. Ensure you have backed up any necessary information before deleting.
</Warning>

## Request

### Path Parameters

<ParamField path="vehicle_id" type="uuid" required>
  The UUID of the vehicle to delete

  **Example:** `550e8400-e29b-41d4-a716-446655440000`
</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

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

## Response

Returns HTTP 204 No Content on successful deletion. No response body.

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X DELETE "https://api.dcycle.io/v1/vehicles/550e8400-e29b-41d4-a716-446655440000" \
    -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")
  vehicle_id = "550e8400-e29b-41d4-a716-446655440000"

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

  response = requests.delete(
      f"https://api.dcycle.io/v1/vehicles/{vehicle_id}",
      headers=headers
  )

  if response.status_code == 204:
      print("Vehicle 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 vehicleId = "550e8400-e29b-41d4-a716-446655440000";

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

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

### Successful Response

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

No response body is returned for successful deletions.

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

### 404 Not Found

**Cause:** Vehicle not found in organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "code": "VEHICLE_NOT_FOUND",
  "detail": "Vehicle with id=UUID('...') not found"
}
```

**Solution:** Verify that the vehicle ID is correct and belongs to your organization. Use the List Vehicles endpoint to get valid IDs.

### 500 Internal Server Error

**Cause:** Server error during deletion

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Internal server error",
  "code": "INTERNAL_ERROR"
}
```

**Solution:** Contact support if the error persists. Provide the vehicle ID and timestamp of the failed deletion.

## Use Cases

### Remove a Decommissioned Vehicle

Delete a vehicle that is no longer in the fleet:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def decommission_vehicle(vehicle_id, license_plate):
    """Remove a decommissioned vehicle from fleet"""
    response = requests.delete(
        f"https://api.dcycle.io/v1/vehicles/{vehicle_id}",
        headers=headers
    )

    if response.status_code == 204:
        print(f"Vehicle {license_plate} successfully decommissioned")
        return True
    else:
        print(f"Failed to delete vehicle: {response.status_code}")
        return False

# Remove vehicle
success = decommission_vehicle(
    "550e8400-e29b-41d4-a716-446655440000",
    "ABC-1234"
)
```

### Clean Up Fleet Duplicates

Remove duplicate entries from your fleet:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def remove_duplicate_vehicles(duplicate_ids):
    """Remove duplicate vehicle entries"""
    deleted = []
    failed = []

    for vehicle_id in duplicate_ids:
        response = requests.delete(
            f"https://api.dcycle.io/v1/vehicles/{vehicle_id}",
            headers=headers
        )

        if response.status_code == 204:
            deleted.append(vehicle_id)
        else:
            failed.append(vehicle_id)

    return {
        "deleted_count": len(deleted),
        "failed_count": len(failed),
        "failed_ids": failed
    }

# Remove duplicates
result = remove_duplicate_vehicles([
    "550e8400-e29b-41d4-a716-446655440000",
    "550e8400-e29b-41d4-a716-446655440001"
])

print(f"Deleted: {result['deleted_count']}, Failed: {result['failed_count']}")
```

### Batch Delete Vehicles

Remove multiple vehicles in bulk:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def bulk_delete_vehicles(vehicle_ids):
    """Delete multiple vehicles"""
    results = {
        "success": 0,
        "failed": 0,
        "errors": []
    }

    for vehicle_id in vehicle_ids:
        try:
            response = requests.delete(
                f"https://api.dcycle.io/v1/vehicles/{vehicle_id}",
                headers=headers
            )

            if response.status_code == 204:
                results["success"] += 1
            else:
                results["failed"] += 1
                results["errors"].append({
                    "vehicle_id": vehicle_id,
                    "status": response.status_code
                })
        except Exception as e:
            results["failed"] += 1
            results["errors"].append({
                "vehicle_id": vehicle_id,
                "error": str(e)
            })

    return results

# Bulk delete example
ids_to_delete = [
    "550e8400-e29b-41d4-a716-446655440000",
    "550e8400-e29b-41d4-a716-446655440001",
    "550e8400-e29b-41d4-a716-446655440002"
]

results = bulk_delete_vehicles(ids_to_delete)
print(f"Deleted: {results['success']}, Failed: {results['failed']}")
if results['errors']:
    print(f"Errors: {results['errors']}")
```

## Best Practices

### Before Deletion

1. **Verify the Vehicle ID**: Ensure you have the correct vehicle ID
2. **Check Dependencies**: Confirm the vehicle has no active consumptions or related data
3. **Backup Information**: Consider exporting vehicle data if needed
4. **Notify Team**: Alert relevant stakeholders before deleting from shared fleets

### Alternative to Deletion

If you want to keep the vehicle data for historical records, consider archiving instead:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def archive_vehicle(vehicle_id):
    """Archive a vehicle instead of deleting (if status field supports it)"""
    # Use PATCH to set status to archived
    response = requests.patch(
        f"https://api.dcycle.io/v1/vehicles/{vehicle_id}",
        headers=headers,
        json={"status": "archived"}
    )

    return response.json()
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Vehicles" icon="list" href="/api-reference/vehicles/list">
    Retrieve all vehicles with filtering and pagination
  </Card>

  <Card title="Create Vehicle" icon="plus" href="/api-reference/vehicles/create">
    Add a new vehicle to your fleet
  </Card>

  <Card title="Update Vehicle" icon="pencil" href="/api-reference/vehicles/update">
    Modify vehicle details
  </Card>

  <Card title="Vehicle Overview" icon="car" href="/api-reference/vehicles/overview">
    Learn about the Vehicles API
  </Card>
</CardGroup>
