# Bulk delete runs

> Source: https://docs.clonepartner.com/api-reference/runs/bulk-delete-runs/

`POST /api/runs/bulk-delete`

Deletes multiple runs by explicit IDs or by filter criteria.
Active runs are skipped. Logs, metrics, and job_run_tasks references are cleaned up before deletion.
Provide exactly one of `ids` or `where`.

**Operation ID:** `bulkDeleteRuns`

## Authentication

### Option 1

- **BearerAuth** (`http bearer`)
  API key token. Create via POST /api/api-keys. Format: `envoy_<hex>`

### Option 2

- **CookieAuth** (`apiKey`)
  Session cookie set after login + TOTP verification

## Request body

The request body is required.

### `application/json`

- Type: `object`
- Properties:
  - `ids` (`array<integer>`) — Explicit run IDs to delete
    - Description: Explicit run IDs to delete
    - Items:
      - Type: `integer`
  - `where` (`object`) — Filter criteria — deletes all matching runs
    - Description: Filter criteria — deletes all matching runs
    - Properties:
      - `status` (`string`)
        - Allowed values: `pending`, `running`, `success`, `completed`, `failed`, `cancelled`
      - `task_id` (`integer`)

## Success responses

### 200

Bulk delete result

**Content type:** `application/json`

- Type: `object`
- Properties:
  - `deleted_count` (`integer`, `required`)
  - `skipped_count` (`integer`, `required`)
  - `skipped` (`array<object>`, `required`)
    - Items:
      - Type: `object`
      - Properties:
        - `id` (`integer`)
        - `reason` (`string`)

## Error responses

### 400

Invalid request (missing or conflicting parameters)

**Content type:** `application/json`

- Reference: `Error`
  - Type: `object`
  - Properties:
    - `error` (`string`)
      - Example: `NOT_FOUND`
    - `message` (`string`)
      - Example: `Resource not found`

## Examples

### cURL

```bash
curl --request POST \
  --url 'https://your-envoy.example.com/api/runs/bulk-delete' \
  --header 'Authorization: Bearer $API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "ids": [
    0
  ],
  "where": {
    "status": "pending",
    "task_id": 0
  }
}'
```

### JavaScript (fetch)

```javascript
const response = await fetch('https://your-envoy.example.com/api/runs/bulk-delete', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "ids": [
      0
    ],
    "where": {
      "status": "pending",
      "task_id": 0
    }
  }),
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = response.status === 204 ? null : await response.json();
console.log(data);
```
