> ## 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 Custom Emission Group

> Remove a custom emission group and all its emission factors

# Delete Custom Emission Group

Permanently delete a custom emission group and all emission factors within it. This action cannot be undone.

<Warning>
  Deleting a custom emission group is permanent and will also delete all custom emission factors within the group. If any factors are in use by purchases, wastes, or energy records, this may affect 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="id" type="string" required>
  UUID of the Custom Emission Group to delete
</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/custom_emission_groups/group-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")
  }

  group_id = "group-uuid"

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

  if response.status_code == 204:
      print("✅ Custom emission group deleted successfully")
  ```

  ```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 groupId = 'group-uuid';

  axios.delete(
    `https://api.dcycle.io/api/v1/custom_emission_groups/${groupId}`,
    { headers }
  )
  .then(response => {
    if (response.status === 204) {
      console.log('✅ Custom emission group deleted successfully');
    }
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

## Use Cases

### Safe Delete with Confirmation

Check group contents before deleting:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Get group details
group = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_groups/{group_id}",
    headers=headers
).json()

# Get factors in the group
factors = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_factors/list/{group_id}",
    headers=headers,
    params={"page": 1, "size": 100}
).json()

print(f"About to delete group: {group['name']}")
print(f"This will also delete {factors['total']} emission factors")

# Confirm and delete
confirmed = True  # Replace with actual user confirmation
if confirmed:
    requests.delete(
        f"https://api.dcycle.io/api/v1/custom_emission_groups/{group_id}",
        headers=headers
    )
    print("✅ Group deleted")
```

### Delete Empty Groups

Clean up groups with no factors:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
groups = requests.get(
    "https://api.dcycle.io/api/v1/custom_emission_groups",
    headers=headers,
    params={"page": 1, "size": 100}
).json()

for group in groups['items']:
    # Check if group has factors
    factors = requests.get(
        f"https://api.dcycle.io/api/v1/custom_emission_factors/list/{group['id']}",
        headers=headers,
        params={"page": 1, "size": 1}
    ).json()

    if factors['total'] == 0:
        requests.delete(
            f"https://api.dcycle.io/api/v1/custom_emission_groups/{group['id']}",
            headers=headers
        )
        print(f"Deleted empty group: {group['name']}")
```

## Common Errors

### 404 Not Found

**Cause:** Custom emission group not found

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Custom emission group not found",
  "code": "NOT_FOUND"
}
```

**Solution:** The group may have already been deleted.

## Best Practices

### 1. Audit Before Deletion

Always check what will be deleted:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
group = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_groups/{group_id}",
    headers=headers
).json()

factors = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_factors/list/{group_id}",
    headers=headers,
    params={"page": 1, "size": 100}
).json()

print(f"Group: {group['name']}")
print(f"Category: {group['category']}")
print(f"Factors: {factors['total']}")

for factor in factors['items']:
    print(f"  - {factor['ef_name']}")
```

### 2. Consider Factor Deletion First

Delete individual factors instead of the entire group if some factors are still needed:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Delete specific factors instead of the whole group
factors_to_delete = ["factor-id-1", "factor-id-2"]

for factor_id in factors_to_delete:
    requests.delete(
        f"https://api.dcycle.io/api/v1/custom_emission_factors/{factor_id}",
        headers=headers
    )
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Group" icon="magnifying-glass" href="/api-docs/custom-emission-groups/get">
    View before deleting
  </Card>

  <Card title="List Factors" icon="list" href="/api-docs/custom-emission-factors/list">
    Check group contents
  </Card>
</CardGroup>
