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

# Update Invoice

> Update an existing invoice

# Update Invoice

Updates an existing invoice with the provided fields. This is a partial update (PATCH), meaning only the fields included in the request body will be modified.

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

### Path Parameters

<ParamField path="invoice_id" type="UUID" required>
  The unique identifier of the invoice to update.

  **Example:** `550e8400-e29b-41d4-a716-446655440000`
</ParamField>

### Body

<ParamField body="uploaded_by" type="UUID">
  ID of the user who uploaded the invoice.
</ParamField>

<ParamField body="facility_id" type="UUID">
  ID of the facility to associate with this invoice.
</ParamField>

<ParamField body="supplier_id" type="UUID">
  ID of the energy supplier.
</ParamField>

<ParamField body="status" type="string">
  Invoice status.

  **Allowed values:** `uploaded`, `loading`, `active`, `inactive`, `review`, `error`
</ParamField>

<ParamField body="invoice_id" type="string">
  Invoice number/identifier from the utility provider.
</ParamField>

<ParamField body="cups" type="string">
  CUPS code for electricity invoices (Spanish market).
</ParamField>

<ParamField body="enabled" type="boolean">
  Whether the invoice is enabled and included in emission calculations.
</ParamField>

<ParamField body="self_consumption" type="boolean">
  Whether this is a self-consumption invoice (electricity only).
</ParamField>

## Response

Returns a lightweight confirmation with core invoice fields. Use [GET /v1/invoices/{id}](/api-reference/invoices/get) for the full detail view.

<ResponseField name="id" type="string">
  UUID of the invoice
</ResponseField>

<ResponseField name="type" type="string">
  Invoice type: `electricity`, `heat`, `water`, `recharge`, or `process`
</ResponseField>

<ResponseField name="status" type="string">
  Invoice status: `uploaded`, `loading`, `active`, `inactive`, `review`, or `error`
</ResponseField>

<ResponseField name="facility_id" type="string | null">
  UUID of the associated facility
</ResponseField>

<ResponseField name="uploaded_by" type="string | null">
  UUID of the user who uploaded the invoice
</ResponseField>

<ResponseField name="supplier_id" type="string | null">
  UUID of the energy supplier
</ResponseField>

<ResponseField name="invoice_id" type="string | null">
  Invoice number/identifier from the utility provider
</ResponseField>

<ResponseField name="cups" type="string | null">
  CUPS code for electricity invoices (Spanish market)
</ResponseField>

<ResponseField name="enabled" type="boolean | null">
  Whether the invoice is enabled and included in calculations
</ResponseField>

<ResponseField name="self_consumption" type="boolean | null">
  Whether this is a self-consumption invoice (electricity only)
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X PATCH "https://api.dcycle.io/v1/invoices/550e8400-e29b-41d4-a716-446655440000" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{
      "status": "active",
      "invoice_id": "INV-2024-001-UPDATED"
    }'
  ```

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

  invoice_id = "550e8400-e29b-41d4-a716-446655440000"

  response = requests.patch(
      f"https://api.dcycle.io/v1/invoices/{invoice_id}",
      headers={
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "Content-Type": "application/json",
      },
      json={
          "status": "active",
          "invoice_id": "INV-2024-001-UPDATED",
      },
  )

  updated_invoice = response.json()
  print(f"Invoice updated: {updated_invoice['id']}")
  ```

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

  const invoiceId = '550e8400-e29b-41d4-a716-446655440000';

  const response = await axios.patch(
    `https://api.dcycle.io/v1/invoices/${invoiceId}`,
    {
      status: 'active',
      invoice_id: 'INV-2024-001-UPDATED',
    },
    {
      headers: {
        'x-organization-id': process.env.DCYCLE_ORG_ID,
        'x-api-key': process.env.DCYCLE_API_KEY,
        'Content-Type': 'application/json',
      },
    }
  );

  console.log(`Invoice updated: ${response.data.id}`);
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "type": "electricity",
  "status": "active",
  "facility_id": "660e8400-e29b-41d4-a716-446655440000",
  "uploaded_by": "990e8400-e29b-41d4-a716-446655440000",
  "supplier_id": "770e8400-e29b-41d4-a716-446655440000",
  "invoice_id": "INV-2024-001-UPDATED",
  "cups": "ES0021000000000001XX",
  "enabled": true,
  "self_consumption": false
}
```

## 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 invoice does not belong to the specified organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Invoice does not belong to this organization",
  "code": "INVOICE_ACCESS_DENIED"
}
```

### 404 Not Found

**Cause:** No invoice exists with the given ID

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

### 422 Validation Error

**Cause:** Invalid field values in the request body (e.g. unknown status)

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "status"],
      "msg": "value is not a valid enumeration member",
      "type": "type_error.enum"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Invoice" icon="file-invoice" href="/api-reference/invoices/get">
    Get a single invoice by ID
  </Card>

  <Card title="List Invoices" icon="list" href="/api-reference/invoices/list">
    Retrieve all invoices with filtering
  </Card>

  <Card title="Delete Invoice" icon="trash" href="/api-reference/invoices/delete">
    Remove an invoice
  </Card>

  <Card title="Recalculate" icon="calculator" href="/api-reference/invoices/recalculate">
    Recalculate emissions for invoices
  </Card>
</CardGroup>
