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

# List Facilities

> Retrieve all facilities with filtering and pagination support

# List Facilities

Retrieve a paginated list of facilities in your organization with support for filtering by name, country, type, and status.

## 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="name" type="string">
  Filter facilities by name (partial match, case-insensitive)

  **Example:** `"Madrid"`
</ParamField>

<ParamField query="country" type="string">
  Filter by ISO country code

  **Example:** `"ES"`
</ParamField>

<ParamField query="type" type="string">
  Filter by facility type

  **Example:** `"office"`
</ParamField>

<ParamField query="status[]" type="array[string]">
  Filter by facility status

  **Available values:** `active`, `archived`

  **Example:** `status[]=active`
</ParamField>

<ParamField query="filter_by" type="string">
  Compound filter expression for advanced filtering. Format: `field:value` with `|` for OR.

  **Example:** `name:Madrid|name:Barcelona`
</ParamField>

<ParamField query="page" type="integer" default="1">
  Page number for pagination
</ParamField>

<ParamField query="size" type="integer" default="10">
  Number of items per page (max 100)
</ParamField>

## Response

<ResponseField name="items" type="array[object]">
  Array of facility objects

  <Expandable title="Facility Object">
    <ResponseField name="id" type="string">Unique identifier (UUID)</ResponseField>
    <ResponseField name="name" type="string">Facility name</ResponseField>
    <ResponseField name="address" type="string | null">Physical address</ResponseField>
    <ResponseField name="country" type="string">ISO country code</ResponseField>
    <ResponseField name="type" type="string">Facility type</ResponseField>
    <ResponseField name="status" type="string">Status: `active` or `archived`</ResponseField>
    <ResponseField name="co2e" type="number | null">CO2e emissions in kg</ResponseField>
    <ResponseField name="co2e_biomass" type="number | null">CO2e from biomass</ResponseField>
    <ResponseField name="logistic_factor" type="number | null">Logistic factor (0-1)</ResponseField>
    <ResponseField name="categories" type="array[string] | null">Consumption categories</ResponseField>
    <ResponseField name="cups_list" type="array[string] | null">CUPS codes</ResponseField>
    <ResponseField name="facility_purpose_type" type="string | null">Purpose type</ResponseField>
    <ResponseField name="created_at" type="datetime">Creation timestamp</ResponseField>
    <ResponseField name="updated_at" type="datetime | null">Last update timestamp</ResponseField>

    <ResponseField name="invoices_in_review_count" type="integer">
      Number of enabled invoices linked to this facility with `status='review'`,
      across all categories (electricity, water, heat, recharge). Defaults to `0`.
    </ResponseField>

    <ResponseField name="categories_without_data" type="integer">
      Number of configured consumption categories that have no enabled invoices. Defaults to `0`.
    </ResponseField>

    <ResponseField name="water_type" type="string | null">
      Water type of the waste water treatment line (only for `waste_water_facilities`)
    </ResponseField>

    <ResponseField name="methane_burned" type="boolean | null">
      Whether methane is burned (only for `waste_water_facilities`)
    </ResponseField>

    <ResponseField name="wwt_line" type="object | null">
      Waste water treatment line config (only for `waste_water_facilities`)

      <Expandable title="WWT Line Object">
        <ResponseField name="id" type="string">Line UUID</ResponseField>
        <ResponseField name="line_code" type="string">Line code identifier</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="sludge_line" type="object | null">
      Sludge treatment line config (only for `waste_water_facilities`)

      <Expandable title="Sludge Line Object">
        <ResponseField name="id" type="string">Line UUID</ResponseField>
        <ResponseField name="line_code" type="string">Line code identifier</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="wwd_line" type="object | null">
      Water discharge line config (only for `waste_water_facilities`)

      <Expandable title="WWD Line Object">
        <ResponseField name="id" type="string">Line UUID</ResponseField>
        <ResponseField name="line_code" type="string">Line code identifier</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="total" type="integer">Total number of facilities matching the filter</ResponseField>
<ResponseField name="page" type="integer">Current page number</ResponseField>
<ResponseField name="size" type="integer">Number of items per page</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X GET "https://api.dcycle.io/v1/facilities?page=1&size=50&status[]=active" \
    -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/facilities",
      headers=headers,
      params={"page": 1, "size": 50, "status[]": ["active"]}
  )

  for facility in response.json()["items"]:
      print(f"{facility['name']}: {facility['co2e'] or 0} kg CO2e")
  ```

  ```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/facilities', {
    headers,
    params: { page: 1, size: 50, 'status[]': ['active'] }
  })
  .then(response => {
    response.data.items.forEach(f => {
      console.log(`${f.name}: ${f.co2e || 0} kg CO2e`);
    });
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "items": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Madrid Office",
      "type": "office",
      "country": "ES",
      "address": "Calle Gran Vía 1, Madrid",
      "status": "active",
      "co2e": 1250.5,
      "co2e_biomass": 0.0,
      "logistic_factor": 0.8,
      "categories": ["heat", "electricity", "water"],
      "cups_list": ["ES0021000000000001AA"],
      "facility_purpose_type": "facilities",
      "created_at": "2024-11-24T10:30:00Z",
      "updated_at": "2024-11-24T10:30:00Z",
      "invoices_in_review_count": 2,
      "categories_without_data": 0,
      "water_type": null,
      "methane_burned": null,
      "wwt_line": null,
      "sludge_line": null,
      "wwd_line": null
    }
  ],
  "total": 12,
  "page": 1,
  "size": 50
}
```

## 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="Create Facility" icon="plus" href="/api-reference/facilities/create">
    Add a new facility
  </Card>

  <Card title="Get Facility" icon="building" href="/api-reference/facilities/get">
    Retrieve a single facility
  </Card>
</CardGroup>
