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));import requests
url = "https://api.dcycle.io/v1/employees/{employee_id}"
headers = {
"x-api-key": "<x-api-key>",
"x-organization-id": "<x-organization-id>"
}
response = requests.delete(url, headers=headers)
print(response.text)curl --request DELETE \
--url https://api.dcycle.io/v1/employees/{employee_id} \
--header 'x-api-key: <x-api-key>' \
--header 'x-organization-id: <x-organization-id>'Delete Employee
Remove an employee from your organization
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));import requests
url = "https://api.dcycle.io/v1/employees/{employee_id}"
headers = {
"x-api-key": "<x-api-key>",
"x-organization-id": "<x-organization-id>"
}
response = requests.delete(url, headers=headers)
print(response.text)curl --request DELETE \
--url https://api.dcycle.io/v1/employees/{employee_id} \
--header 'x-api-key: <x-api-key>' \
--header 'x-organization-id: <x-organization-id>'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
string
required
Your API key for authenticationExample:
sk_live_1234567890abcdefstring
required
Your organization UUIDExample:
a8315ef3-dd50-43f8-b7ce-d839e68d51faPath Parameters
string
required
The unique identifier (UUID) of the employee to deleteExample:
550e8400-e29b-41d4-a716-446655440000Response
Returns204 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}"
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}")
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
Common Errors
401 Unauthorized
Cause: Missing or invalid API key{
"detail": "Invalid API key",
"code": "INVALID_API_KEY"
}
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"
}
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:- Update to Terminated: Set
situation: "terminated"to preserve historical data - Archive Data: Export employee data before deletion for records
- 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
Related Endpoints
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
Was this page helpful?