> ## 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 Workforce Trainings by Filters

> Delete every training record matching a set of filters, guarded by the hash of the list you saw

[← Own Workforce API](/api-reference/own-workforce/overview)

Delete every training matching a filter set, without collecting ids. Filters go in the **query string** — the same ones [List Workforce Trainings Paginated](/api-reference/own-workforce/list-trainings-paginated) accepts — and the body carries the `filter_hash` that list returned.

## The filter\_hash guard

`filter_hash` fingerprints the filters that produced a page, including `consolidate_group` and `organization_id[]`. Send it back; the server recomputes the fingerprint from the filters on *this* request. Match, and the delete proceeds over exactly the set you listed. Differ, and it answers `409 Conflict` without deleting anything.

That is what stops a client from listing one subsidiary and then, after widening the perimeter, deleting the whole group. It guards against that drift, not against a caller who deliberately sends different filters — the tenant boundary is the organization scoping, not the hash. Take the hash verbatim from the list response.

At least one real filter is required. `consolidate_group` and `organization_id[]` do not count: they change the perimeter rather than select rows, so on their own they answer `422`. That blocks a *filterless* call, not a broad one: a single wide `created_at_from` satisfies the rule and can still match every row, so read `total` from the list before you delete.

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

### Query Parameters

<ParamField query="file_id[]" type="array[string]">
  Filter by source upload file. The nil UUID matches rows with no file.
</ParamField>

<ParamField query="created_at_from" type="datetime">
  Only rows created at or after this instant
</ParamField>

<ParamField query="created_at_to" type="datetime">
  Only rows created on or before this instant, inclusive
</ParamField>

<ParamField query="search" type="string">
  Free-text search, up to 255 characters
</ParamField>

<ParamField query="consolidate_group" type="boolean" default="false">
  Widen the perimeter to the accepted family. Part of the hash; does not satisfy the "at least one filter" rule.
</ParamField>

<ParamField query="organization_id[]" type="array[string]">
  Narrow a group-view delete to these organizations. Part of the hash; does not satisfy the "at least one filter" rule.
</ParamField>

### Body

<ParamField body="filter_hash" type="string" required>
  The `filter_hash` from the paginated list response that showed you these rows
</ParamField>

## Response

Same shape as [Bulk Delete Workforce Trainings](/api-reference/own-workforce/bulk-delete-trainings): `success_count`, `success_ids`, `failed_count`, `failed_ids` and `message`.

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/own_workforce_trainings/bulk-delete-by-filters?file_id[]=aa11bb22-cc33-4d44-8e55-ff6677889900" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{"filter_hash": "4e8a1c07d3b95f26"}'
  ```

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

  import requests

  headers = {
      "x-api-key": os.getenv("DCYCLE_API_KEY"),
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
  }

  filters = {"file_id[]": "aa11bb22-cc33-4d44-8e55-ff6677889900"}

  listed = requests.get(
      "https://api.dcycle.io/v1/own_workforce_trainings/paginated",
      headers=headers,
      params=filters,
  ).json()
  print(f"about to delete {listed['total']} trainings")

  response = requests.post(
      "https://api.dcycle.io/v1/own_workforce_trainings/bulk-delete-by-filters",
      headers=headers,
      params=filters,
      json={"filter_hash": listed["filter_hash"]},
  )

  print(response.json()["message"])
  ```

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

  const headers = {
    'x-api-key': process.env.DCYCLE_API_KEY,
    'x-organization-id': process.env.DCYCLE_ORG_ID
  };

  const params = { 'file_id[]': 'aa11bb22-cc33-4d44-8e55-ff6677889900' };

  axios.get('https://api.dcycle.io/v1/own_workforce_trainings/paginated', { headers, params })
    .then(listed => axios.post(
      'https://api.dcycle.io/v1/own_workforce_trainings/bulk-delete-by-filters',
      { filter_hash: listed.data.filter_hash },
      { headers, params }
    ))
    .then(({ data }) => console.log(data.message))
    .catch(error => console.error(error));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "success_count": 320,
  "success_ids": [
    "… 320 ids in total, abridged here …",
    "3d9b0a11-2c4e-4f6a-8b1d-5e7f9a0c2d4e"],
  "failed_count": 0,
  "failed_ids": [],
  "message": "Deleted 320 training records"
}
```

## Common Errors

### 401 Unauthorized

**Cause:** the key is invalid, or it does not belong to the organization in `x-organization-id` — the two are looked up as a pair. A request carrying no credentials at all answers `AUTH_REQUIRED` instead.

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

### 403 Forbidden

**Cause:** the key's owner is not an enabled member of the organization, or their role cannot write.

```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:** `filter_hash` does not match the filters on this request. Nothing was deleted.

```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 real filter was supplied — only `consolidate_group` and/or `organization_id[]`, or nothing at all.

```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="List trainings paginated" icon="list-ol" href="/api-reference/own-workforce/list-trainings-paginated">
    Where `filter_hash` comes from
  </Card>

  <Card title="Bulk delete by ids" icon="trash" href="/api-reference/own-workforce/bulk-delete-trainings">
    When you already hold the ids
  </Card>
</CardGroup>
