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

# Create Waste Water Facility

> Create a waste water treatment facility with treatment line configuration

# Create Waste Water Facility

Create a new waste water treatment (WWT) facility in your organization. Unlike standard facilities, WWT facilities require configuration of three treatment lines:

* **WWT line** — waste water treatment process
* **Sludge line** — sludge treatment process
* **WWD line** — waste water discharge process

Each line determines the CH4 and N2O emission factors used when calculating the facility's GHG emissions.

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

### Body Parameters

<ParamField body="name" type="string" required>
  Name of the facility

  **Example:** `"Barcelona WWTP"`
</ParamField>

<ParamField body="type" type="string" required>
  Facility type

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

<ParamField body="country" type="string">
  ISO 3166-1 country code

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

<ParamField body="address" type="string">
  Physical address of the facility

  **Example:** `"Passeig de la Zona Franca 101, Barcelona"`
</ParamField>

<ParamField body="wwt_line_id" type="string" required>
  UUID of the waste water treatment line configuration
</ParamField>

<ParamField body="sludge_line_id" type="string" required>
  UUID of the sludge treatment line configuration
</ParamField>

<ParamField body="wwd_line_id" type="string" required>
  UUID of the waste water discharge line configuration
</ParamField>

<ParamField body="methane_burned" type="boolean">
  Whether methane from the treatment process is captured and burned (flared). If `true`, CH4 emissions are reduced.
</ParamField>

<ParamField body="categories" type="array[string]">
  Consumption categories enabled for this facility

  **Example:** `["water"]`
</ParamField>

<ParamField body="status" type="string">
  Facility status

  **Available values:** `active`, `archived`
</ParamField>

## Response (201 Created)

<ResponseField name="id" type="string">
  UUID of the created facility
</ResponseField>

<ResponseField name="name" type="string">
  Facility name
</ResponseField>

<ResponseField name="type" type="string">
  Facility type
</ResponseField>

<ResponseField name="country" type="string">
  Country code
</ResponseField>

<ResponseField name="address" type="string | null">
  Facility address
</ResponseField>

<ResponseField name="facility_purpose_type" type="string">
  Always `"waste_water"` for WWT facilities
</ResponseField>

<ResponseField name="wwt_line_id" type="string">
  UUID of the waste water treatment line
</ResponseField>

<ResponseField name="sludge_line_id" type="string">
  UUID of the sludge treatment line
</ResponseField>

<ResponseField name="wwd_line_id" type="string">
  UUID of the waste water discharge line
</ResponseField>

<ResponseField name="methane_burned" type="boolean | null">
  Whether methane is captured and burned
</ResponseField>

<ResponseField name="created_at" type="datetime">
  Creation timestamp
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/facilities/waste_water" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Barcelona WWTP",
      "type": "waste_water",
      "country": "ES",
      "address": "Passeig de la Zona Franca 101, Barcelona",
      "wwt_line_id": "wwt-line-uuid",
      "sludge_line_id": "sludge-line-uuid",
      "wwd_line_id": "wwd-line-uuid",
      "methane_burned": true,
      "categories": ["water"]
    }'
  ```

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

  response = requests.post(
      "https://api.dcycle.io/v1/facilities/waste_water",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
          "Content-Type": "application/json",
      },
      json={
          "name": "Barcelona WWTP",
          "type": "waste_water",
          "country": "ES",
          "address": "Passeig de la Zona Franca 101, Barcelona",
          "wwt_line_id": "wwt-line-uuid",
          "sludge_line_id": "sludge-line-uuid",
          "wwd_line_id": "wwd-line-uuid",
          "methane_burned": True,
          "categories": ["water"],
      },
  )

  facility = response.json()
  print(f"Created WWT facility: {facility['id']} — {facility['name']}")
  ```

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

  const { data: facility } = await axios.post(
    'https://api.dcycle.io/v1/facilities/waste_water',
    {
      name: 'Barcelona WWTP',
      type: 'waste_water',
      country: 'ES',
      address: 'Passeig de la Zona Franca 101, Barcelona',
      wwt_line_id: 'wwt-line-uuid',
      sludge_line_id: 'sludge-line-uuid',
      wwd_line_id: 'wwd-line-uuid',
      methane_burned: true,
      categories: ['water'],
    },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
        'Content-Type': 'application/json',
      },
    }
  );

  console.log(`Created: ${facility.id} — ${facility.name}`);
  ```
</CodeGroup>

### Successful Response (201)

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Barcelona WWTP",
  "type": "waste_water",
  "country": "ES",
  "address": "Passeig de la Zona Franca 101, Barcelona",
  "status": "active",
  "facility_purpose_type": "waste_water",
  "wwt_line_id": "wwt-line-uuid",
  "sludge_line_id": "sludge-line-uuid",
  "wwd_line_id": "wwd-line-uuid",
  "methane_burned": true,
  "co2e": null,
  "co2e_biomass": null,
  "created_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 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"}
```

### 422 Unprocessable Entity

**Cause:** Missing required fields or invalid treatment line UUIDs

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "wwt_line_id"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Create Facility" icon="plus" href="/api-reference/facilities/create">
    Create a standard facility
  </Card>

  <Card title="List Facilities" icon="list" href="/api-reference/facilities/list">
    Retrieve all facilities
  </Card>

  <Card title="Waste Water Treatments" icon="droplet" href="/api-reference/waste-water-treatments/list">
    List waste water treatment records
  </Card>
</CardGroup>
