> ## 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 purchases by ID in a single request

# Bulk Delete

Delete multiple purchases by their IDs. All purchases must belong to the requesting organization. Related emission records (`total_impacts`) are automatically deleted to maintain referential integrity.

Returns detailed results for each ID, allowing you to handle partial failures gracefully.

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

## Response

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

<ResponseField name="failed" type="object[]">
  Failed deletions with reason:

  | Field    | Type   | Description                   |
  | -------- | ------ | ----------------------------- |
  | `id`     | string | The purchase UUID that failed |
  | `reason` | string | Why the deletion failed       |
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/purchases/bulk-delete" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "purchase_ids": [
        "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      ]
    }'
  ```

  ```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/purchases/bulk-delete",
      headers=headers,
      json={
          "purchase_ids": [
              "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
              "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          ]
      },
  )

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

  ```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/purchases/bulk-delete', {
    purchase_ids: [
      'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
      'b2c3d4e5-f6a7-8901-bcde-f12345678901',
    ],
  }, { headers })
  .then(response => {
    const { deleted, failed } = response.data;
    console.log(`Deleted: ${deleted.length} | Failed: ${failed.length}`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "deleted": [
    "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "b2c3d4e5-f6a7-8901-bcde-f12345678901"
  ],
  "failed": []
}
```

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

**Cause:** Empty array or more than 100,000 IDs

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "purchase_ids"],
      "msg": "ensure this value has at least 1 items",
      "type": "value_error.list.min_items"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Bulk Delete by Filters" icon="filter" href="/api-reference/purchases/bulk-delete-by-filters">
    Delete all purchases matching filter criteria
  </Card>

  <Card title="List Purchases" icon="list" href="/api-reference/purchases/list">
    Browse and filter purchases
  </Card>
</CardGroup>
