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

> Remove an employee from your organization

[← Employees API](https://code.dcycle.io/api-reference/employees/overview.md)

> [!WARNING]
>
> **Deprecated.** Use [`POST /v2/employees/delete`](https://code.dcycle.io/api-reference/employees/delete-v2): many employees per request by id, idempotent, deleted asynchronously as an ingest job, with webhooks. This endpoint keeps working; its responses carry `Deprecation` and `Link: </v2/employees/delete>; rel="successor-version"` headers. Its responses also carry `Sunset: Fri, 30 Apr 2027 00:00:00 GMT`: the endpoint is retired on **April 30, 2027** (see the [changelog](https://code.dcycle.io/api-reference/changelog.md)).

Permanently delete an employee from your organization. This will also remove all associated commuting periods and their CO2e data.

> [!WARNING]
>
> **Irreversible Action**: Deleting an employee permanently removes all their data, including commuting history and emissions calculations. Consider updating the `situation` to `terminated` instead if you want to preserve historical data.

## Request

### Headers

**x-api-key** `string` *required*

Your API key for authentication

**Example:** `sk_live_1234567890abcdef`

**x-organization-id** `string` *required*

Your organization UUID

**Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`

### Path Parameters

**employee\_id** `string` *required*

The unique identifier (UUID) of the employee to delete

**Example:** `550e8400-e29b-41d4-a716-446655440000`

## Response

Returns `204 No Content` on successful deletion. No response body is returned.

## Example

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X DELETE "https://api.dcycle.io/v1/employees/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")
employee_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/employees/{employee_id}",
    headers=headers
)

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

```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 employeeId = '550e8400-e29b-41d4-a716-446655440000';

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

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

### Successful Response

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

No response body is returned.

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

### 404 Not Found

**Cause:** Employee not found or doesn't belong to your organization

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

**Solution:** Verify the employee ID is correct and belongs to your organization.

## Use Cases

### Delete Single Employee

Remove an employee from the system:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def delete_employee(employee_id):
    """Delete an employee by ID"""
    response = requests.delete(
        f"https://api.dcycle.io/v1/employees/{employee_id}",
        headers=headers
    )

    if response.status_code == 204:
        return True
    else:
        print(f"Failed to delete: {response.text}")
        return False

success = delete_employee("550e8400-e29b-41d4-a716-446655440000")
if success:
    print("Employee deleted")
```

### Delete with Confirmation

Verify before deleting:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def delete_employee_with_confirmation(employee_id):
    """Delete employee after getting confirmation"""
    # First, get employee details
    response = requests.get(
        f"https://api.dcycle.io/v1/employees/{employee_id}",
        headers=headers
    )

    if response.status_code != 200:
        print("Employee not found")
        return False

    employee = response.json()

    # Show what will be deleted
    total_co2e = sum(p['co2e'] for p in employee.get('periods', []))
    print(f"About to delete:")
    print(f"  Name: {employee['name']}")
    print(f"  Email: {employee['email']}")
    print(f"  Periods: {len(employee.get('periods', []))}")
    print(f"  Total CO2e: {total_co2e} kg")

    # In a real app, you'd ask for confirmation here
    confirm = input("Delete this employee? (yes/no): ")

    if confirm.lower() == 'yes':
        response = requests.delete(
            f"https://api.dcycle.io/v1/employees/{employee_id}",
            headers=headers
        )
        return response.status_code == 204

    return False
```

### Bulk Delete Employees

Delete multiple employees:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def bulk_delete_employees(employee_ids):
    """Delete multiple employees"""
    results = {"deleted": [], "failed": []}

    for emp_id in employee_ids:
        response = requests.delete(
            f"https://api.dcycle.io/v1/employees/{emp_id}",
            headers=headers
        )

        if response.status_code == 204:
            results["deleted"].append(emp_id)
        else:
            results["failed"].append({
                "id": emp_id,
                "error": response.text
            })

    return results

# Delete multiple employees
employee_ids = [
    "550e8400-e29b-41d4-a716-446655440000",
    "550e8400-e29b-41d4-a716-446655440001"
]

results = bulk_delete_employees(employee_ids)
print(f"Deleted: {len(results['deleted'])}")
print(f"Failed: {len(results['failed'])}")
```

### Delete Terminated Employees

Clean up terminated employees:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def cleanup_terminated_employees():
    """Delete all terminated employees"""
    # Get all terminated employees
    response = requests.get(
        "https://api.dcycle.io/v1/employees",
        headers=headers,
        params={"situation": ["terminated"], "size": 100}
    )

    employees = response.json()["items"]
    print(f"Found {len(employees)} terminated employees")

    deleted = 0
    for emp in employees:
        response = requests.delete(
            f"https://api.dcycle.io/v1/employees/{emp['id']}",
            headers=headers
        )
        if response.status_code == 204:
            deleted += 1
            print(f"Deleted: {emp['name'] or emp['email']}")

    print(f"Total deleted: {deleted}")
    return deleted

# Run cleanup
cleanup_terminated_employees()
```

> [!TIP]
>
> **Consider Alternatives**
>
> Before deleting, consider:
>
> 1. **Update to Terminated**: Set `situation: "terminated"` to preserve historical data
> 2. **Archive Data**: Export employee data before deletion for records
> 3. **Verify Impact**: Check if the employee's CO2e data is needed for reports
>
> **Preserve Historical Data**
>
> If you need to keep emissions records:
>
> ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
> def archive_and_delete_employee(employee_id):
>     """Archive employee data before deletion"""
>     # Get employee with full data
>     response = requests.get(
>         f"https://api.dcycle.io/v1/employees/{employee_id}",
>         headers=headers
>     )
>     employee = response.json()
>
>     # Archive to file or database
>     import json
>     with open(f"archived_employee_{employee_id}.json", "w") as f:
>         json.dump(employee, f, indent=2)
>
>     print(f"Archived employee data to archived_employee_{employee_id}.json")
>
>     # Now delete
>     response = requests.delete(
>         f"https://api.dcycle.io/v1/employees/{employee_id}",
>         headers=headers
>     )
>
>     return response.status_code == 204
> ```

## Related Endpoints

> [card] [Update Employee](https://code.dcycle.io/api-reference/employees/update.md)
>
> Modify employee (e.g., set as terminated instead of deleting)

> [card] [List Employees](https://code.dcycle.io/api-reference/employees/list.md)
>
> View all employees

> [card] [Create Employee](https://code.dcycle.io/api-reference/employees/create.md)
>
> Add a new employee

> [card] [Get Employee](https://code.dcycle.io/api-reference/employees/get.md)
>
> View employee details before deleting


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.