Skip to main content
DELETE
https://api.dcycle.io
/
api
/
v1
/
custom_emission_factors
/
{id}
Delete Custom Emission Factor
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/custom_emission_factors/{id}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

Delete Custom Emission Factor

Permanently delete a custom emission factor from a Custom Emission Group. This action cannot be undone.
Deleting a custom emission factor is permanent. If the factor is currently in use by purchases, wastes, or other records, this may affect historical data calculations. Consider archiving by setting end dates instead of deleting.

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

id
string
required
UUID of the Custom Emission Factor to deleteExample: "factor-uuid-here"

Response

Returns HTTP 204 No Content on successful deletion.

Example

curl -X DELETE "https://api.dcycle.io/api/v1/custom_emission_factors/factor-uuid" \
  -H "Authorization: Bearer ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "x-user-id: ${DCYCLE_USER_ID}"

Use Cases

Remove Outdated Factors

Delete factors that are no longer relevant:
# Get all factors in a 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()

# Delete outdated factors
from datetime import date

today = date.today()
for factor in factors['items']:
    if factor['factor_end_date'] and date.fromisoformat(factor['factor_end_date']) < today:
        requests.delete(
            f"https://api.dcycle.io/api/v1/custom_emission_factors/{factor['id']}",
            headers=headers
        )
        print(f"Deleted expired factor: {factor['ef_name']}")

Safe Delete with Confirmation

Always fetch and confirm before deleting:
async function deleteFactorSafely(factorId) {
  // First, get the factor details
  const factor = await axios.get(
    `https://api.dcycle.io/api/v1/custom_emission_factors/${factorId}`,
    { headers }
  ).then(res => res.data);

  // Show confirmation
  console.log(`About to delete: ${factor.ef_name}`);
  console.log(`Uploaded by: ${factor.factor_uploaded_by}`);
  console.log(`Valid until: ${factor.factor_end_date}`);

  // Confirm and delete
  const confirmed = true; // Replace with actual user confirmation
  if (confirmed) {
    await axios.delete(
      `https://api.dcycle.io/api/v1/custom_emission_factors/${factorId}`,
      { headers }
    );
    console.log('✅ Deleted successfully');
  }
}

Bulk Delete by Criteria

Delete multiple factors matching certain criteria:
# List all factors in a group
response = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_factors/list/{group_id}",
    headers=headers,
    params={"page": 1, "size": 100}
)

factors = response.json()['items']

# Delete factors with high uncertainty
for factor in factors:
    if factor.get('uncertainty_grade', 0) > 80:
        requests.delete(
            f"https://api.dcycle.io/api/v1/custom_emission_factors/{factor['id']}",
            headers=headers
        )
        print(f"Deleted high-uncertainty factor: {factor['ef_name']} ({factor['uncertainty_grade']}%)")

Common Errors

404 Not Found

{
  "detail": "Custom emission factor not found",
  "code": "NOT_FOUND"
}
Solution: The factor may have already been deleted, or the ID is incorrect. Verify the factor exists first.

403 Forbidden

{
  "detail": "Insufficient permissions",
  "code": "FORBIDDEN"
}
Solution: Ensure you have permission to delete factors for this organization.

Best Practices

1. Archive Instead of Delete

For factors with historical usage, consider setting an end date instead of deleting:
# Instead of deleting
# requests.delete(...)

# Archive by setting end date to yesterday
from datetime import date, timedelta

yesterday = date.today() - timedelta(days=1)
requests.patch(
    f"https://api.dcycle.io/api/v1/custom_emission_factors/{factor_id}",
    headers=headers,
    json={
        "factor_uploaded_by": "[email protected]",
        "factor_end_date": yesterday.isoformat(),
        "additional_docs": f"{factor['additional_docs']} | Archived {date.today().isoformat()}"
    }
)
Note: The API doesn’t allow updating factor_end_date via PATCH. If you need to archive, you must delete and recreate with the updated date, or simply delete if no longer needed.

2. Audit Before Deleting

Check if factor is in use before deletion:
# Get factor details
factor = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_factors/{factor_id}",
    headers=headers
).json()

print(f"Factor: {factor['ef_name']}")
print(f"Created: {factor.get('factor_start_date', 'Unknown')}")
print(f"Uploaded by: {factor['factor_uploaded_by']}")

# Confirm before proceeding
confirm = input("Delete this factor? (yes/no): ")
if confirm.lower() == 'yes':
    requests.delete(
        f"https://api.dcycle.io/api/v1/custom_emission_factors/{factor_id}",
        headers=headers
    )

3. Clean Up Empty Groups

After deleting factors, check if the group is empty:
# Delete factor
requests.delete(
    f"https://api.dcycle.io/api/v1/custom_emission_factors/{factor_id}",
    headers=headers
)

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

if remaining['total'] == 0:
    print(f"Group {group_id} is now empty. Consider deleting the group.")
    # Optionally delete the group
    # requests.delete(f"https://api.dcycle.io/api/v1/custom_emission_groups/{group_id}", headers=headers)

4. Log Deletion Actions

Maintain audit logs of deletions:
async function deleteWithAudit(factorId, reason) {
  const factor = await axios.get(
    `https://api.dcycle.io/api/v1/custom_emission_factors/${factorId}`,
    { headers }
  ).then(res => res.data);

  // Log before deletion
  const auditLog = {
    action: 'delete_custom_emission_factor',
    factor_id: factorId,
    factor_name: factor.ef_name,
    deleted_by: process.env.DCYCLE_USER_ID,
    deleted_at: new Date().toISOString(),
    reason: reason
  };
  console.log('Audit log:', auditLog);
  // Save to your audit system

  // Delete
  await axios.delete(
    `https://api.dcycle.io/api/v1/custom_emission_factors/${factorId}`,
    { headers }
  );
}

// Usage
deleteWithAudit('factor-uuid', 'Supplier no longer in use');