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

> Delete multiple invoices by ID

# Bulk Delete

Delete multiple invoices by their IDs. Invoices must belong to the specified facility and match the given type. Related emission records and distributed siblings are automatically cleaned up.

## 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="invoice_ids" type="string[]" required>
  Array of invoice UUIDs to delete (1–100,000)
</ParamField>

<ParamField body="facility_id" type="string" required>
  UUID of the facility the invoices belong to
</ParamField>

<ParamField body="type" type="string" required>
  Invoice type: `electricity`, `heat`, `water`, `recharge`
</ParamField>

## Response

<ResponseField name="success_count" type="integer">
  Number of invoices successfully deleted
</ResponseField>

<ResponseField name="success_ids" type="string[]">
  UUIDs of successfully deleted invoices
</ResponseField>

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

<ResponseField name="failed_ids" type="string[]">
  UUIDs of invoices that failed to delete
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable summary message
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/invoices/bulk-delete" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "invoice_ids": ["uuid-1", "uuid-2"],
      "facility_id": "'${FACILITY_ID}'",
      "type": "electricity"
    }'
  ```

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

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

  response = requests.post(
      "https://api.dcycle.io/v1/invoices/bulk-delete",
      headers=headers,
      json={
          "invoice_ids": ["uuid-1", "uuid-2"],
          "facility_id": os.getenv("FACILITY_ID"),
          "type": "electricity",
      },
  )

  result = response.json()
  print(f"Deleted: {result['success_count']} | Failed: {result['failed_count']}")
  ```

  ```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,
    'Content-Type': 'application/json',
  };

  axios.post('https://api.dcycle.io/v1/invoices/bulk-delete', {
    invoice_ids: ['uuid-1', 'uuid-2'],
    facility_id: process.env.FACILITY_ID,
    type: 'electricity',
  }, { headers })
  .then(response => {
    const { success_count, failed_count } = response.data;
    console.log(`Deleted: ${success_count} | Failed: ${failed_count}`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "success_count": 2,
  "success_ids": ["uuid-1", "uuid-2"],
  "failed_count": 0,
  "failed_ids": [],
  "message": "Successfully deleted 2 invoices"
}
```

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

### 422 Unprocessable Entity

**Cause:** Missing required fields or invalid invoice type

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "invoice_ids"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Bulk Delete Preview" icon="eye" href="/api-reference/invoices/bulk-delete-preview">
    Preview what will be deleted before confirming
  </Card>

  <Card title="Bulk Delete by Filters" icon="filter" href="/api-reference/invoices/bulk-delete-by-filters">
    Delete invoices matching filter criteria
  </Card>
</CardGroup>
