> ## 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 Waste Water Treatment

> Edit a measurement period of a waste water facility and recalculate its emissions

Edit a waste water treatment (WWT) record. Only the fields you send change; the rest keep their stored values. Dcycle then recalculates the CH4 and N2O emissions of the period asynchronously: the record answers `status: "loading"` until the new emissions are stored (`uploaded`), or `error` if the calculation fails.

## Request

### Headers

**x-api-key** `string` *required*

Your API key for authentication

**Example:** `sk_live_1234567890abcdef`

**x-organization-id** `string` *required*

Your organization UUID

**Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`

### Path Parameters

**wwt\_id** `string` *required*

UUID of the waste water treatment record. It can belong to your organization or to a subsidiary you can write to.

**Example:** `550e8400-e29b-41d4-a716-446655440000`

### Body Parameters

Every field is optional and takes the same values as in [the create](https://code.dcycle.io/api-reference/waste-water-treatments/create.md#body-parameters). Only `kg_r_wwt_line`, `kg_r_sludge_line`, `file_url` and `file_id` accept `null`.

**name** `string`

Name or reference of the measurement. Returned as `invoice_id`.

**start\_date** `date`

Start of the measured period (`YYYY-MM-DD`). The period, with the stored date you do not send, must not end before it starts.

**end\_date** `date`

End of the measured period (`YYYY-MM-DD`)

**m3\_water\_in** `number`

Influent water volume (m³), `0` or greater. Like every numeric field below.

**m3\_water\_out** `number`

Effluent water volume (m³)

**kg\_sludge** `number`

Sludge produced (kg)

**kg\_bod\_per\_m3\_wwt\_line** `number`

BOD concentration of the influent, WWT line (kg BOD/m³)

**kg\_bod\_per\_kg\_sludge\_line** `number`

BOD content of the sludge, sludge line (kg BOD/kg sludge)

**kg\_bod\_per\_m3\_wwd\_line** `number`

BOD concentration of the effluent, WWD line (kg BOD/m³)

**kg\_n\_per\_m3\_wwt\_line** `number`

Nitrogen concentration of the influent, WWT line (kg N/m³)

**kg\_n\_per\_m3\_wwd\_line** `number`

Nitrogen concentration of the effluent, WWD line (kg N/m³)

**kg\_r\_wwt\_line** `number | null`

CH4 recovered in the WWT line (kg)

**kg\_r\_sludge\_line** `number | null`

CH4 recovered in the sludge line (kg)

**file\_url** `string | null`

Supporting document: a URL, or the document itself as a base64 data URI (stored by Dcycle). A different value replaces the stored document and its name; `null` or `""` removes it.

**file\_id** `string | null`

UUID of an uploaded file of My files to attach instead: the record stores its URL and name. `null` removes the attachment. Not together with a data URI in `file_url`.

## Response

Returns `200 OK` with the record in the shape of [GET /v1/waste-water-treatments/`{wwt_id}`/detail](https://code.dcycle.io/api-reference/waste-water-treatments/detail#response), with `status: "loading"`. Fetch the detail later to read the recalculated `co2e`.

## Example

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X PATCH "https://api.dcycle.io/v1/waste-water-treatments/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 '{"m3_water_in": 130000, "kg_sludge": 50000}'
```

## Common Errors

### 404 Not Found

**Cause:** The record does not exist, or it belongs to an organization you cannot write to. Also a `file_id` that is not an uploaded file you may attach to the record.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "WasteWaterTreatment with id='550e8400-e29b-41d4-a716-446655440000' not found",
  "code": "NOT_FOUND"
}
```

### 422 Validation Error

**Cause:** A negative number, `null` on a field that takes none, `end_date` before `start_date` (code `INVALID_DATE_RANGE` when one of them is the stored date), or `file_id` together with a data URI in `file_url`.

## Related Endpoints

> **[Get Waste Water Treatment](https://code.dcycle.io/api-reference/waste-water-treatments/detail.md)**
>
> Read a record and its calculated emissions

> **[Delete Waste Water Treatments](https://code.dcycle.io/api-reference/waste-water-treatments/delete-v2.md)**
>
> Delete records by id with their emissions


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.