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

> Apply the same field changes to multiple invoices by ID

# Bulk Update

Apply the same set of field changes to many invoices at once. Only the fields exposed by the bulk-edit UI (`unit_id`, `currency_unit_id`, `supplier_id`, `cups`) can be updated; every other field on each invoice is left untouched.

Each selected invoice's whole distributed group receives the change, so a distributed invoice never ends up with different units or supplier across facilities. Selecting more than one row of the same group updates that group exactly once.

When a change affects the emission calculation (`supplier_id` or `unit_id`), recalculation is triggered asynchronously: the affected invoices move to `loading` and settle once the recalculation finishes. Changing only `currency_unit_id` or `cups` updates the value as plain metadata and triggers no recalculation.

Per-invoice failures are reported in `failed_ids` instead of aborting the batch. Invoice IDs that do not belong to your organization are also returned in `failed_ids`.

## 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 update (1–10,000)
</ParamField>

<ParamField body="update" type="object" required>
  Fields to apply to every selected invoice. At least one field must be provided.

  <Expandable title="update">
    <ParamField body="unit_id" type="string">
      UUID of the unit of the quantity. Cannot be set to `null`.
    </ParamField>

    <ParamField body="currency_unit_id" type="string">
      UUID of the fiat-currency unit of the monetary spend. Does not affect the emission calculation.
    </ParamField>

    <ParamField body="supplier_id" type="string">
      UUID of the supplier (provider).
    </ParamField>

    <ParamField body="cups" type="string">
      CUPS supply-point code (electricity). Does not affect the emission calculation.
    </ParamField>
  </Expandable>
</ParamField>

## Response

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

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

<ResponseField name="failed_count" type="integer">
  Number of invoices that failed to update or were not found
</ResponseField>

<ResponseField name="failed_ids" type="string[]">
  UUIDs of invoices that failed to update or were not found
</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-update" \
    -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"],
      "update": {
        "supplier_id": "'${SUPPLIER_ID}'"
      }
    }'
  ```

  ```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-update",
      headers=headers,
      json={
          "invoice_ids": ["uuid-1", "uuid-2"],
          "update": {"supplier_id": os.getenv("SUPPLIER_ID")},
      },
  )

  result = response.json()
  print(f"Updated: {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-update', {
    invoice_ids: ['uuid-1', 'uuid-2'],
    update: { supplier_id: process.env.SUPPLIER_ID },
  }, { headers })
  .then(response => {
    const { success_count, failed_count } = response.data;
    console.log(`Updated: ${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 updated 2 invoice(s)"
}
```

## 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:** No fields provided in `update`, an explicit `null` `unit_id`, or a `supplier_id` that does not exist

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Supplier not found", "code": "SUPPLIER_ID_NOT_FOUND"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Update Invoice" icon="pen" href="/api-reference/invoices/update">
    Update a single invoice
  </Card>

  <Card title="Bulk Delete" icon="trash" href="/api-reference/invoices/bulk-delete">
    Delete multiple invoices by ID
  </Card>
</CardGroup>
