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

# Get Invoice

> Retrieve a specific invoice by its ID with full detail including emissions data

# Get Invoice

Retrieve detailed information about a specific invoice using its unique identifier. The response shape varies based on the invoice `type` field (discriminated union).

## 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="string" required>
  The unique identifier (UUID) of the invoice to retrieve

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

## Response

The response is a discriminated union based on the `type` field. All invoice types share common fields, with additional fields depending on the type.

### Common Fields

<ResponseField name="id" type="string">
  Unique identifier (UUID) for the invoice
</ResponseField>

<ResponseField name="type" type="string">
  Invoice type that determines the response shape

  **Available values:** `heat`, `electricity`, `water`, `recharge`, `process`
</ResponseField>

<ResponseField name="quantity" type="number">
  Consumption amount after facility allocation
</ResponseField>

<ResponseField name="base_quantity" type="number">
  Original consumption amount before facility allocation
</ResponseField>

<ResponseField name="percentage" type="number">
  Facility allocation percentage (0-1)
</ResponseField>

<ResponseField name="status" type="string">
  Current invoice status

  **Available values:** `uploaded`, `loading`, `active`, `inactive`, `review`, `error`
</ResponseField>

<ResponseField name="co2e" type="number">
  Calculated CO2 equivalent emissions (kg)
</ResponseField>

<ResponseField name="co2e_biomass" type="number">
  CO2 equivalent biomass emissions (kg)
</ResponseField>

<ResponseField name="start_date" type="datetime">
  Billing period start date
</ResponseField>

<ResponseField name="end_date" type="datetime">
  Billing period end date
</ResponseField>

<ResponseField name="unit_id" type="string | null">
  Unit of measurement UUID
</ResponseField>

<ResponseField name="facility_id" type="string | null">
  Associated facility UUID
</ResponseField>

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

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

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

<ResponseField name="file_id" type="string | null">
  UUID of the linked file (if created via bulk import or PDF upload)
</ResponseField>

<ResponseField name="file_url" type="string | null">
  URL to download the linked file
</ResponseField>

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

<ResponseField name="created_at" type="datetime">
  Timestamp when the invoice was created
</ResponseField>

<ResponseField name="updated_at" type="datetime | null">
  Timestamp when the invoice was last updated
</ResponseField>

<ResponseField name="base_total_spend" type="number | null">
  Total spend before facility allocation (in the invoice currency)
</ResponseField>

<ResponseField name="total_spend" type="number | null">
  Total spend after facility allocation
</ResponseField>

<ResponseField name="currency_unit_id" type="string | null">
  UUID of the currency unit for spend fields
</ResponseField>

<ResponseField name="user" type="object | null">
  User who uploaded the invoice

  <Expandable title="User Object">
    <ResponseField name="id" type="string">User UUID</ResponseField>
    <ResponseField name="first_name" type="string | null">First name</ResponseField>
    <ResponseField name="last_name" type="string | null">Last name</ResponseField>
    <ResponseField name="email" type="string | null">Email address</ResponseField>
    <ResponseField name="prefix" type="string | null">Phone prefix</ResponseField>
    <ResponseField name="phone_number" type="string | null">Phone number</ResponseField>
    <ResponseField name="onboarding_done" type="boolean | null">Whether onboarding is complete</ResponseField>
    <ResponseField name="profile_img_url" type="string | null">Profile image URL</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="facility_percentages" type="array[object] | null">
  Facility percentage allocations

  <Expandable title="Facility Percentage Object">
    <ResponseField name="organization_id" type="string">
      The organization UUID
    </ResponseField>

    <ResponseField name="facility_id" type="string">
      The facility UUID
    </ResponseField>

    <ResponseField name="percentage" type="number">
      The percentage allocation (0-1)
    </ResponseField>

    <ResponseField name="company_name" type="string">
      The company name
    </ResponseField>

    <ResponseField name="facility_name" type="string">
      The facility name
    </ResponseField>
  </Expandable>
</ResponseField>

### Type-Specific Fields

The following fields are included depending on the invoice `type`:

| Field                       | Types                             | Description                                |
| --------------------------- | --------------------------------- | ------------------------------------------ |
| `supplier_id`               | `heat`, `electricity`, `recharge` | Energy supplier UUID                       |
| `facility_fuel_id`          | `heat`, `recharge`                | Fuel type UUID                             |
| `stationary_fuel_id`        | `heat`, `recharge`                | Stationary fuel UUID                       |
| `stationary_fuel`           | `heat`, `recharge`                | Stationary fuel object (`id`, `name`)      |
| `refrigerant_fuel_id`       | `recharge`                        | Refrigerant fuel UUID                      |
| `refrigerant_fuel`          | `recharge`                        | Refrigerant fuel object (`id`, `name`)     |
| `self_consumption`          | `electricity`                     | Whether this is a self-consumption invoice |
| `custom_emission_factor_id` | `heat`, `electricity`, `recharge` | Custom emission factor UUID                |
| `custom_emission_factor`    | `heat`, `electricity`, `recharge` | Custom emission factor details (object)    |

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X GET "https://api.dcycle.io/v1/invoices/550e8400-e29b-41d4-a716-446655440000" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}"
  ```

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

  api_key = os.getenv("DCYCLE_API_KEY")
  org_id = os.getenv("DCYCLE_ORG_ID")

  headers = {
      "x-api-key": api_key,
      "x-organization-id": org_id
  }

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

  response = requests.get(
      f"https://api.dcycle.io/v1/invoices/{invoice_id}",
      headers=headers
  )

  invoice = response.json()
  print(f"Type: {invoice['type']}")
  print(f"Quantity: {invoice['quantity']} (base: {invoice['base_quantity']})")
  print(f"CO2e: {invoice['co2e']} kg")
  ```

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

  const apiKey = process.env.DCYCLE_API_KEY;
  const orgId = process.env.DCYCLE_ORG_ID;

  const headers = {
    'x-api-key': apiKey,
    'x-organization-id': orgId
  };

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

  axios.get(
    `https://api.dcycle.io/v1/invoices/${invoiceId}`,
    { headers }
  )
  .then(response => {
    const invoice = response.data;
    console.log(`Type: ${invoice.type}`);
    console.log(`Quantity: ${invoice.quantity} (base: ${invoice.base_quantity})`);
    console.log(`CO2e: ${invoice.co2e} kg`);
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

### Successful Response

**Electricity invoice example:**

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "type": "electricity",
  "quantity": 1500.00,
  "base_quantity": 3000.00,
  "percentage": 0.5,
  "status": "active",
  "co2e": 245.5,
  "co2e_biomass": 0,
  "start_date": "2024-01-01T00:00:00",
  "end_date": "2024-01-31T23:59:59",
  "unit_id": "ba80e6cb-86a4-4bb1-a0c5-8104365d523c",
  "facility_id": "660e8400-e29b-41d4-a716-446655440000",
  "uploaded_by": "990e8400-e29b-41d4-a716-446655440000",
  "invoice_id": "INV-2024-001",
  "cups": "ES0021000000000001XX",
  "file_id": null,
  "file_url": "https://storage.dcycle.io/invoices/invoice-2024-001.pdf",
  "enabled": true,
  "created_at": "2024-02-01T10:30:00Z",
  "updated_at": "2024-02-01T10:30:00Z",
  "base_total_spend": 285.50,
  "total_spend": 142.75,
  "currency_unit_id": "eur-uuid",
  "user": {
    "id": "990e8400-e29b-41d4-a716-446655440000",
    "first_name": "Ana",
    "last_name": "García",
    "email": "ana@company.com",
    "prefix": null,
    "phone_number": null,
    "onboarding_done": true,
    "profile_img_url": null
  },
  "facility_percentages": [
    {
      "organization_id": "a8315ef3-dd50-43f8-b7ce-d839e68d51fa",
      "facility_id": "660e8400-e29b-41d4-a716-446655440000",
      "percentage": 0.5,
      "company_name": "Acme Corp",
      "facility_name": "Madrid Office"
    }
  ],
  "supplier_id": "770e8400-e29b-41d4-a716-446655440000",
  "self_consumption": false,
  "custom_emission_factor_id": null,
  "custom_emission_factor": null
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Invalid API key",
  "code": "INVALID_API_KEY"
}
```

**Solution:** Verify your API key is valid and active.

### 404 Not Found

**Cause:** Invoice not found or doesn't belong to your organization

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

**Solution:** Verify the invoice ID exists and belongs to the organization specified in the header.

### 422 Validation Error

**Cause:** Invalid invoice ID format

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["path", "invoice_id"],
      "msg": "value is not a valid uuid",
      "type": "type_error.uuid"
    }
  ]
}
```

**Solution:** Ensure the invoice ID is a valid UUID format.

## Use Cases

### Check Invoice Emissions by Type

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def get_invoice_emissions(invoice_id):
    """Get invoice and display type-specific emissions info"""
    response = requests.get(
        f"https://api.dcycle.io/v1/invoices/{invoice_id}",
        headers=headers
    )

    invoice = response.json()
    inv_type = invoice["type"]

    print(f"Type: {inv_type}")
    print(f"CO2e: {invoice['co2e']} kg")
    print(f"CO2e biomass: {invoice['co2e_biomass']} kg")

    if inv_type in ("heat", "electricity", "recharge") and invoice.get("custom_emission_factor"):
        print(f"Custom EF: {invoice['custom_emission_factor']}")

    return invoice

invoice = get_invoice_emissions("550e8400-e29b-41d4-a716-446655440000")
```

### Verify Facility Allocation

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def check_facility_allocation(invoice_id):
    """Check how an invoice is allocated across facilities"""
    response = requests.get(
        f"https://api.dcycle.io/v1/invoices/{invoice_id}",
        headers=headers
    )
    invoice = response.json()

    if invoice.get("facility_percentages"):
        for alloc in invoice["facility_percentages"]:
            print(f"{alloc['facility_name']} ({alloc['company_name']}): {alloc['percentage'] * 100}%")
    else:
        print(f"Single facility: {invoice.get('facility_id')}")

check_facility_allocation("550e8400-e29b-41d4-a716-446655440000")
```

## Related Endpoints

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

  <Card title="Update Invoice" icon="pencil" href="/api-reference/invoices/update">
    Modify invoice details
  </Card>

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

  <Card title="Invoices Overview" icon="book" href="/api-reference/invoices/overview">
    Learn about the Invoices API
  </Card>
</CardGroup>
