Skip to main content
DELETE
/
v1
/
employees
/
{employee_id}
Delete Employee
const options = {
  method: 'DELETE',
  headers: {'x-api-key': '<x-api-key>', 'x-organization-id': '<x-organization-id>'}
};

fetch('https://api.dcycle.io/v1/employees/{employee_id}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

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

Permanently delete an employee from your organization. This will also remove all associated commuting periods and their CO2e data.
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 authenticationExample: sk_live_1234567890abcdef
x-organization-id
string
required
Your organization UUIDExample: a8315ef3-dd50-43f8-b7ce-d839e68d51fa

Path Parameters

employee_id
string
required
The unique identifier (UUID) of the employee to deleteExample: 550e8400-e29b-41d4-a716-446655440000

Response

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

Example

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}"

Successful Response

HTTP/1.1 204 No Content
No response body is returned.

Common Errors

401 Unauthorized

Cause: Missing or invalid API key
{
  "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
{
  "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:
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:
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:
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:
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()

Best Practices

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

Update Employee

Modify employee (e.g., set as terminated instead of deleting)

List Employees

View all employees

Create Employee

Add a new employee

Get Employee

View employee details before deleting