Skip to main content
DELETE
https://api.dcycle.io
/
api
/
v1
/
waste_water_treatments
/
{waste_water_treatment_id}
Delete Waste Water Treatment
const options = {
  method: 'DELETE',
  headers: {
    'x-api-key': '<x-api-key>',
    'x-organization-id': '<x-organization-id>',
    'x-user-id': '<x-user-id>'
  }
};

fetch('https://api.dcycle.io/api/v1/waste_water_treatments/{waste_water_treatment_id}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

Delete Waste Water Treatment

Permanently delete a specific waste water treatment record. This action cannot be undone.
Deleting a waste water treatment record is permanent and will affect your facility’s emission calculations and historical data.

Request

Headers

x-api-key
string
required
Your API key for authenticationExample: sk_live_1234567890abcdef
x-organization-id
string
required
Your organization UUIDExample: ff4adcc7-8172-45fe-9cf1-e90a6de53aa9
x-user-id
string
required
Your user UUIDExample: a1b2c3d4-e5f6-7890-abcd-ef1234567890

Path Parameters

waste_water_treatment_id
string
required
UUID of the waste water treatment record to deleteExample: "treatment-uuid-here"

Response

Returns HTTP 204 No Content on successful deletion.

Example

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

Use Cases

Delete Erroneous Records

Remove incorrectly uploaded records:
# 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:
# 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:
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

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

{
  "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:
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:
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:
# 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
)