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

> Retrieve a single facility by its ID

# Get Facility

Retrieve detailed information about a specific facility in your organization.

## Request

### Path Parameters

<ParamField path="facility_id" type="uuid" required>
  The UUID of the facility to retrieve

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

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

## Response

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

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X GET "https://api.dcycle.io/v1/facilities/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

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

  facility_id = "550e8400-e29b-41d4-a716-446655440000"
  response = requests.get(
      f"https://api.dcycle.io/v1/facilities/{facility_id}",
      headers=headers
  )

  facility = response.json()
  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
  };

  const facilityId = '550e8400-e29b-41d4-a716-446655440000';
  axios.get(`https://api.dcycle.io/v1/facilities/${facilityId}`, { headers })
    .then(response => console.log(response.data));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "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",
  "invoices_in_review_count": 0,
  "categories_without_data": 0,
  "water_type": null,
  "methane_burned": null,
  "wwt_line": null,
  "sludge_line": null,
  "wwd_line": null,
  "created_at": "2024-11-24T10:30:00Z",
  "updated_at": "2024-11-24T10:30:00Z"
}
```

## 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 user is not a member of the organization, or facility does not belong to the organization specified in `x-organization-id`

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Facility doesn't belong to organization"
}
```

### 404 Not Found

**Cause:** Facility with the given ID does not exist

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "code": "NOT_FOUND",
  "detail": "Facility with id=UUID('...') not found"
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Facilities" icon="list" href="/api-reference/facilities/list">
    Retrieve all facilities
  </Card>

  <Card title="Update Facility" icon="pencil" href="/api-reference/facilities/update">
    Modify facility details
  </Card>
</CardGroup>
