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

> Modify an existing facility's details

# Update Facility

Update an existing facility in your organization. Only include the fields you want to change — all other fields remain unchanged.

<Warning>
  **Archiving Side Effects**: Setting `status` to `archived` will also archive any linked logistic hub and deactivate associated supply contracts.
</Warning>

## Request

### Path Parameters

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

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

### Body Parameters

All fields are optional — only include what you want to change.

<ParamField body="name" type="string">Facility name</ParamField>
<ParamField body="address" type="string">Physical address</ParamField>
<ParamField body="country" type="string">ISO country code</ParamField>
<ParamField body="type" type="string">Facility type</ParamField>
<ParamField body="categories" type="array[string]">Consumption categories</ParamField>
<ParamField body="cups_list" type="array[string]">CUPS codes</ParamField>
<ParamField body="status" type="string">Status: `active` or `archived`</ParamField>
<ParamField body="logistic_factor" type="number">Logistic factor (0 to 1)</ParamField>

## Response

Returns the updated facility object.

<ResponseField name="id" type="string">
  Facility 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="categories" type="array[string] | null">
  Enabled consumption categories
</ResponseField>

<ResponseField name="cups_list" type="array[string] | null">
  List of CUPS codes
</ResponseField>

<ResponseField name="status" type="string">
  Facility status: `active` or `archived`
</ResponseField>

<ResponseField name="co2e" type="number | null">
  Total CO2e emissions (tCO2e)
</ResponseField>

<ResponseField name="co2e_biomass" type="number | null">
  CO2e emissions from biomass sources
</ResponseField>

<ResponseField name="logistic_factor" type="number | null">
  Logistic factor for scope 2 (0 to 1)
</ResponseField>

<ResponseField name="facility_purpose_type" type="string | null">
  Purpose type of the facility
</ResponseField>

<ResponseField name="created_at" type="datetime">
  Creation timestamp (ISO 8601)
</ResponseField>

<ResponseField name="updated_at" type="string | null">
  Last update timestamp (ISO 8601)
</ResponseField>

<ResponseField name="invoices_in_review_count" type="integer">
  Number of invoices in `review` status
</ResponseField>

<ResponseField name="categories_without_data" type="integer">
  Number of configured categories with no invoices
</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 PUT "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}" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Madrid HQ",
      "categories": ["heat", "electricity", "water", "recharge"]
    }'
  ```

  ```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"),
      "Content-Type": "application/json"
  }

  facility_id = "550e8400-e29b-41d4-a716-446655440000"
  response = requests.put(
      f"https://api.dcycle.io/v1/facilities/{facility_id}",
      headers=headers,
      json={"name": "Madrid HQ", "categories": ["heat", "electricity", "water", "recharge"]}
  )

  print(f"Updated: {response.json()['name']}")
  ```

  ```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,
    'Content-Type': 'application/json'
  };

  const facilityId = '550e8400-e29b-41d4-a716-446655440000';
  axios.put(`https://api.dcycle.io/v1/facilities/${facilityId}`, {
    name: "Madrid HQ",
    categories: ["heat", "electricity", "water", "recharge"]
  }, { headers })
  .then(response => console.log(`Updated: ${response.data.name}`));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Madrid HQ",
  "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", "recharge"],
  "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-12-01T15:45: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 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"}
```

### 404 Not Found

**Cause:** The facility does not exist or belongs to another organization

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

### 422 Unprocessable Entity

**Cause:** Invalid field values (e.g. invalid country code or status)

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "country"],
      "msg": "Invalid country code",
      "type": "value_error"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Facility" icon="building" href="/api-reference/facilities/get">
    Retrieve facility details
  </Card>

  <Card title="Delete Facility" icon="trash" href="/api-reference/facilities/delete">
    Remove a facility
  </Card>
</CardGroup>
