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

# Bulk Delete by Filters

> Delete all employees matching filter criteria

# Bulk Delete by Filters

Delete all employees that match the given filter criteria. Uses the same filters as the list endpoint. Requires a `filter_hash` for optimistic concurrency — the hash must match what the server computes for the same filters, ensuring the user deletes exactly what they saw.

## Request

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

### Body Parameters

<ParamField body="filter_hash" type="string" required>
  Hash from the list endpoint response (`filter_hash` field). Prevents stale deletes.
</ParamField>

### Query Parameters (Filters)

<ParamField query="search" type="string">
  Free-text search across employee fields
</ParamField>

<ParamField query="transport_type[]" type="string[]">
  Filter by transport type (car, bus, metro, train, bicycle, etc.)
</ParamField>

<ParamField query="situation[]" type="string[]">
  Filter by employee situation
</ParamField>

<ParamField query="status[]" type="string[]">
  Filter by calculation status: `pending`, `active`, `error`
</ParamField>

<ParamField query="response_medium[]" type="string[]">
  Filter by survey response medium
</ParamField>

<ParamField query="file_id[]" type="string[]">
  Filter by bulk-upload file UUIDs
</ParamField>

<ParamField query="created_at_from" type="string">
  Filter records created on or after this datetime (ISO 8601)
</ParamField>

<ParamField query="created_at_to" type="string">
  Filter records created on or before this datetime (ISO 8601)
</ParamField>

<ParamField query="co2e_status" type="string">
  Filter by CO2e calculation status
</ParamField>

## Response

<ResponseField name="total" type="integer">
  Total number of employees processed
</ResponseField>

<ResponseField name="success" type="integer">
  Number of employees successfully deleted
</ResponseField>

<ResponseField name="failed" type="integer">
  Number of employees that failed to delete
</ResponseField>

<ResponseField name="errors" type="array[object]">
  Details of failed deletions
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v2/employees/bulk-delete-by-filters?file_id[]=file-uuid-1" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{"filter_hash": "abc123def456"}'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  response = requests.post(
      "https://api.dcycle.io/v2/employees/bulk-delete-by-filters",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
          "Content-Type": "application/json",
      },
      params={"file_id[]": "file-uuid-1"},
      json={"filter_hash": "abc123def456"},
  )

  result = response.json()
  print(f"Deleted {result['success']}/{result['total']} employees from file")
  ```

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

  const { data } = await axios.post(
    'https://api.dcycle.io/v2/employees/bulk-delete-by-filters',
    { filter_hash: 'abc123def456' },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
        'Content-Type': 'application/json',
      },
      params: { 'file_id[]': 'file-uuid-1' },
    }
  );

  console.log(`Deleted ${data.success}/${data.total} employees from file`);
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "total": 85,
  "success": 85,
  "failed": 0,
  "errors": []
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

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

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 409 Conflict

**Cause:** The `filter_hash` doesn't match the current filter state — data changed since the list was loaded

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Filter hash mismatch. The filters have changed since the list was loaded. Please refresh and try again."
}
```

### 422 Unprocessable Entity

**Cause:** No filter parameters provided (safety check to prevent accidental mass deletion)

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "At least one filter parameter is required for bulk delete by filters."
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Bulk Delete" icon="trash" href="/api-reference/employees/bulk-delete">
    Delete employees by specific IDs
  </Card>

  <Card title="List Employees" icon="list" href="/api-reference/employees/list">
    Retrieve all employees with filtering and pagination
  </Card>
</CardGroup>
