Skip to main content
POST
/
v1
/
invoices
/
bulk-delete-by-filters
Bulk Delete by Filters
const options = {
  method: 'POST',
  headers: {
    'x-api-key': '<x-api-key>',
    'x-organization-id': '<x-organization-id>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({filter_hash: '<string>'})
};

fetch('https://api.dcycle.io/v1/invoices/bulk-delete-by-filters', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
{
  "success_count": 123,
  "success_ids": [
    "<string>"
  ],
  "failed_count": 123,
  "failed_ids": [
    "<string>"
  ],
  "message": "<string>"
}

Bulk Delete by Filters

Delete all invoices that match the given filter criteria. Uses the same filters as the list endpoint plus a filter_hash for optimistic concurrency — ensuring you delete exactly what the user saw.

Request

Headers

x-api-key
string
required
Your API key for authenticationExample: sk_live_1234567890abcdef
x-organization-id
string
required
Your organization UUIDExample: a8315ef3-dd50-43f8-b7ce-d839e68d51fa

Query Parameters

At least one filter parameter (beyond facility_id and type) is required.
facility_id
string
required
UUID of the facility
type
string
required
Invoice type: electricity, heat, water, recharge
start_date
string
Filter invoices on or after this date
end_date
string
Filter invoices on or before this date
status[]
string[]
Filter by status
co2e_status
string
Filter by CO2e calculation status
cups[]
string[]
Filter by CUPS identifier
supplier_id[]
string[]
Filter by supplier UUID

Body Parameters

filter_hash
string
required
Hash from the list endpoint response. Must match the current filter set.

Example

# Step 1: Get filter_hash from list
RESPONSE=$(curl -s "https://api.dcycle.io/v1/invoices?facility_id=${FACILITY_ID}&type=electricity&status[]=error" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}")

FILTER_HASH=$(echo $RESPONSE | jq -r '.filter_hash')

# Step 2: Bulk delete with the same filters
curl -X POST "https://api.dcycle.io/v1/invoices/bulk-delete-by-filters?facility_id=${FACILITY_ID}&type=electricity&status[]=error" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d "{\"filter_hash\": \"${FILTER_HASH}\"}"

Successful Response

{
  "success_count": 2,
  "success_ids": [
    "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "b2c3d4e5-f6a7-8901-bcde-f12345678901"
  ],
  "failed_count": 0,
  "failed_ids": [],
  "message": "Successfully deleted 2 invoices"
}

Response

success_count
integer
Number of invoices successfully deleted
success_ids
string[]
UUIDs of successfully deleted invoices
failed_count
integer
Number of invoices that failed to delete
failed_ids
string[]
UUIDs of invoices that failed to delete
message
string
Human-readable summary message

Common Errors

401 Unauthorized

Cause: Missing or invalid API key
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}

403 Forbidden

Cause: The authenticated user is not a member of the organization
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}

409 Conflict

Cause: filter_hash doesn’t match — filters changed since the list was loaded
{
  "detail": "Filter hash mismatch. The filters have changed since the list was loaded. Please refresh and try again."
}

422 Unprocessable Entity

Cause: No narrowing filter provided beyond facility_id and type
{
  "detail": "At least one filter parameter is required for bulk delete by filters."
}

Bulk Delete

Delete specific invoices by ID

Bulk Delete Preview

Preview what will be deleted