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

# Delete Waste Water Treatment

> Remove a waste water treatment record

# Delete Waste Water Treatment

Permanently delete a specific waste water treatment record. This action cannot be undone.

<Warning>
  Deleting a waste water treatment record is permanent and will affect your facility's emission calculations and historical data.
</Warning>

## 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:** `ff4adcc7-8172-45fe-9cf1-e90a6de53aa9`
</ParamField>

<ParamField header="x-user-id" type="string" required>
  Your user UUID

  **Example:** `a1b2c3d4-e5f6-7890-abcd-ef1234567890`
</ParamField>

### Path Parameters

<ParamField path="waste_water_treatment_id" type="string" required>
  UUID of the waste water treatment record to delete

  **Example:** `"treatment-uuid-here"`
</ParamField>

## Response

Returns HTTP 204 No Content on successful deletion.

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X DELETE "https://api.dcycle.io/api/v1/waste_water_treatments/treatment-uuid" \
    -H "Authorization: Bearer ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "x-user-id: ${DCYCLE_USER_ID}"
  ```

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

  headers = {
      "Authorization": f"Bearer {os.getenv('DCYCLE_API_KEY')}",
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "x-user-id": os.getenv("DCYCLE_USER_ID")
  }

  treatment_id = "treatment-uuid"

  response = requests.delete(
      f"https://api.dcycle.io/api/v1/waste_water_treatments/{treatment_id}",
      headers=headers
  )

  if response.status_code == 204:
      print("✅ Waste water treatment record deleted successfully")
  else:
      print(f"❌ Error: {response.json()}")
  ```

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

  const headers = {
    'Authorization': `Bearer ${process.env.DCYCLE_API_KEY}`,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'x-user-id': process.env.DCYCLE_USER_ID
  };

  const treatmentId = 'treatment-uuid';

  axios.delete(
    `https://api.dcycle.io/api/v1/waste_water_treatments/${treatmentId}`,
    { headers }
  )
  .then(response => {
    if (response.status === 204) {
      console.log('✅ Waste water treatment record deleted successfully');
    }
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

## Use Cases

### Delete Erroneous Records

Remove incorrectly uploaded records:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Delete a single erroneous record
treatment_id = "treatment-uuid"

response = requests.delete(
    f"https://api.dcycle.io/api/v1/waste_water_treatments/{treatment_id}",
    headers=headers
)

if response.status_code == 204:
    print(f"✅ Deleted treatment record: {treatment_id}")
```

### Bulk Delete by Date Range

Delete multiple records from a specific period:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Note: You need to first fetch the treatment IDs
# (Dcycle API doesn't have a list endpoint for treatments yet)

treatment_ids_to_delete = [
    "treatment-uuid-1",
    "treatment-uuid-2",
    "treatment-uuid-3"
]

for treatment_id in treatment_ids_to_delete:
    response = requests.delete(
        f"https://api.dcycle.io/api/v1/waste_water_treatments/{treatment_id}",
        headers=headers
    )

    if response.status_code == 204:
        print(f"✅ Deleted: {treatment_id}")
    else:
        print(f"❌ Failed to delete: {treatment_id}")
```

### Safe Delete with Confirmation

Implement confirmation before deletion:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
def delete_treatment_with_confirmation(treatment_id):
    # In a real application, you'd fetch treatment details first
    print(f"⚠️ About to delete treatment: {treatment_id}")
    confirmation = input("Are you sure? (yes/no): ")

    if confirmation.lower() == 'yes':
        response = requests.delete(
            f"https://api.dcycle.io/api/v1/waste_water_treatments/{treatment_id}",
            headers=headers
        )

        if response.status_code == 204:
            print("✅ Deleted successfully")
            return True
    else:
        print("❌ Deletion cancelled")
        return False

# Usage
delete_treatment_with_confirmation("treatment-uuid")
```

## Common Errors

### 404 Not Found

**Cause:** Waste water treatment not found

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Waste water treatment not found",
  "code": "NOT_FOUND"
}
```

**Solution:** The treatment record may have already been deleted, or the ID is incorrect.

### 403 Forbidden

**Cause:** Insufficient permissions

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Insufficient permissions",
  "code": "FORBIDDEN"
}
```

**Solution:** Ensure the treatment belongs to your organization and you have permission to delete it.

## Best Practices

### 1. Confirm Before Deleting

Always confirm deletion, especially for production data:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
treatment_id = "treatment-uuid"

# Get treatment details first (if you have the data)
print(f"About to delete treatment: {treatment_id}")

# Confirm
confirmed = True  # Replace with actual user confirmation

if confirmed:
    response = requests.delete(
        f"https://api.dcycle.io/api/v1/waste_water_treatments/{treatment_id}",
        headers=headers
    )
```

### 2. Log Deletions

Maintain audit logs of deletions:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import logging
from datetime import datetime

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def delete_treatment_with_audit(treatment_id, reason):
    logger.info(f"Deleting treatment {treatment_id}. Reason: {reason}")

    response = requests.delete(
        f"https://api.dcycle.io/api/v1/waste_water_treatments/{treatment_id}",
        headers=headers
    )

    if response.status_code == 204:
        logger.info(f"Successfully deleted treatment {treatment_id} at {datetime.utcnow()}")
        return True
    else:
        logger.error(f"Failed to delete treatment {treatment_id}")
        return False

# Usage
delete_treatment_with_audit("treatment-uuid", "Incorrect data uploaded")
```

### 3. Re-upload Instead of Edit

Since there's no UPDATE endpoint, delete and re-upload to correct errors:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Delete incorrect record
requests.delete(
    f"https://api.dcycle.io/api/v1/waste_water_treatments/{treatment_id}",
    headers=headers
)

# Re-upload with corrected data
corrected_data = {
    "facility_id": "facility-uuid",
    "daily_waste_water_treatment_data": [
        {
            "name": "Corrected Daily Treatment 2024-03-01",
            "measurement_date": "2024-03-01",
            "m3_water_in": 38500,  # Corrected value
            "m3_water_out": 30500,  # Corrected value
            # ... all other fields
        }
    ]
}

requests.post(
    "https://api.dcycle.io/api/v1/bulk/waste_water_treatments",
    headers=headers,
    json=corrected_data
)
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Bulk Upload" icon="upload" href="/api-docs/waste-water-treatments/bulk-upload">
    Create treatment records
  </Card>

  <Card title="Facilities" icon="building" href="/api-docs/facilities/list">
    List waste water facilities
  </Card>
</CardGroup>
