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

# Totals

> Get aggregated purchase totals with year-over-year comparison

# Totals

Returns aggregated totals for purchases: total CO2e, total monetary amount (EUR), record count, and percentage change compared to the same period in the previous year. Supports the same filters as the list endpoint.

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

### Query Parameters

<ParamField query="purchase_date_from" type="string">
  Filter purchases on or after this date (ISO format `YYYY-MM-DD`)
</ParamField>

<ParamField query="purchase_date_to" type="string">
  Filter purchases on or before this date (ISO format `YYYY-MM-DD`)
</ParamField>

<ParamField query="search" type="string">
  Search by description or supplier name
</ParamField>

<ParamField query="status[]" type="string[]">
  Filter by status. Values: `active`, `error`, `in_progress`, `in_review`, `inactive`, `pending`
</ParamField>

<ParamField query="purchase_type[]" type="string[]">
  Filter by calculation methodology. Values: `spend_based`, `supplier_specific`
</ParamField>

<ParamField query="expense_type[]" type="string[]">
  Filter by expense classification. Values: `capex`, `opex`
</ParamField>

<ParamField query="file_id[]" type="string[]">
  Filter by file UUID. Use `00000000-0000-0000-0000-000000000000` for manually created records.
</ParamField>

<ParamField query="supplier_id[]" type="string[]">
  Filter by supplier UUID
</ParamField>

<ParamField query="unit_id[]" type="string[]">
  Filter by currency unit UUID
</ParamField>

<ParamField query="created_at_from" type="string">
  Filter records created on or after this date
</ParamField>

<ParamField query="created_at_to" type="string">
  Filter records created on or before this date
</ParamField>

<ParamField query="co2e_status" type="string">
  Filter by CO2e calculation status

  **Allowed values:** `calculated`, `not_calculated`
</ParamField>

<ParamField query="filter_by" type="string">
  Per-column filters using the filter grammar

  **Example:** `quantity:gt100$co2e:bt[10,100]`
</ParamField>

<ParamField query="filter_match" type="string">
  How to combine `filter_by` clauses across fields

  **Allowed values:** `any` (OR), `all` (AND, default)
</ParamField>

<ParamField query="filter_or_fields" type="string">
  Comma-separated fields whose same-field clauses combine with OR instead of AND
</ParamField>

## Response

<ResponseField name="total_co2e" type="number">
  Sum of CO2e (tCO2e) for all matching purchases
</ResponseField>

<ResponseField name="total_amount" type="number">
  Sum of monetary amounts (EUR) for all matching purchases
</ResponseField>

<ResponseField name="count" type="integer">
  Number of matching purchase records
</ResponseField>

<ResponseField name="co2e_pct_change" type="number | null">
  Percentage change in CO2e vs the same period in the previous year. `null` when no prior-year data exists.
</ResponseField>

<ResponseField name="amount_pct_change" type="number | null">
  Percentage change in monetary amount vs the same period in the previous year. `null` when no prior-year data exists.
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X GET "https://api.dcycle.io/v1/purchases/totals?purchase_date_from=2025-01-01&purchase_date_to=2025-12-31" \
    -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

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

  response = requests.get(
      "https://api.dcycle.io/v1/purchases/totals",
      headers=headers,
      params={
          "purchase_date_from": "2025-01-01",
          "purchase_date_to": "2025-12-31",
      },
  )

  totals = response.json()
  print(f"CO2e: {totals['total_co2e']:.2f} tCO2e ({totals['co2e_pct_change']:+.1f}% YoY)")
  print(f"Amount: €{totals['total_amount']:,.2f} | {totals['count']} purchases")
  ```

  ```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,
  };

  axios.get('https://api.dcycle.io/v1/purchases/totals', {
    headers,
    params: {
      purchase_date_from: '2025-01-01',
      purchase_date_to: '2025-12-31',
    },
  })
  .then(response => {
    const { total_co2e, total_amount, count, co2e_pct_change } = response.data;
    console.log(`CO2e: ${total_co2e.toFixed(2)} tCO2e (${co2e_pct_change > 0 ? '+' : ''}${co2e_pct_change}% YoY)`);
    console.log(`Amount: €${total_amount.toLocaleString()} | ${count} purchases`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "total_co2e": 142.75,
  "total_amount": 85230.50,
  "count": 312,
  "co2e_pct_change": -8.3,
  "amount_pct_change": 12.1
}
```

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

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Purchases" icon="list" href="/api-reference/purchases/list">
    Browse purchases with filters and pagination
  </Card>

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