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/purchases/bulk-delete-by-filters', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.dcycle.io/v1/purchases/bulk-delete-by-filters"
payload = { "filter_hash": "<string>" }
headers = {
"x-api-key": "<x-api-key>",
"x-organization-id": "<x-organization-id>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)curl --request POST \
--url https://api.dcycle.io/v1/purchases/bulk-delete-by-filters \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--header 'x-organization-id: <x-organization-id>' \
--data '
{
"filter_hash": "<string>"
}
'{
"deleted": [
"<string>"
],
"failed": [
{}
]
}Bulk Delete by Filters
Delete all purchases matching filter criteria using an optimistic concurrency guard
POST
/
v1
/
purchases
/
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/purchases/bulk-delete-by-filters', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.dcycle.io/v1/purchases/bulk-delete-by-filters"
payload = { "filter_hash": "<string>" }
headers = {
"x-api-key": "<x-api-key>",
"x-organization-id": "<x-organization-id>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)curl --request POST \
--url https://api.dcycle.io/v1/purchases/bulk-delete-by-filters \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--header 'x-organization-id: <x-organization-id>' \
--data '
{
"filter_hash": "<string>"
}
'{
"deleted": [
"<string>"
],
"failed": [
{}
]
}← Purchases API
Delete all purchases that match the given filter criteria. Uses the same filter parameters as the list endpoint, plus a
filter_hash for optimistic concurrency — ensuring you delete exactly what the user saw.
How filter_hash works
- Call the list endpoint with your filters — the response includes a
filter_hash - Pass that
filter_hashin the body of this request along with the same filters - If the filters changed between the two calls, the server returns
409 Conflict
Request
Headers
string
required
Your API key for authenticationExample:
sk_live_1234567890abcdefstring
required
Your organization UUIDExample:
a8315ef3-dd50-43f8-b7ce-d839e68d51faQuery Parameters
No filter is required: without one the delete covers every purchase the unfiltered list shows (the header organization, or under group view the accepted family narrowed byorganization_id[], and the project scope when it is on). Supports all the same filters as the list endpoint:
string
Filter purchases on or after this date (
YYYY-MM-DD)string
Filter purchases on or before this date (
YYYY-MM-DD)string
Search by description or supplier name
string[]
Filter by status. Values:
active, error, in_progress, in_review, inactive, pendingstring[]
Filter by calculation methodology. Values:
spend_based, supplier_specificstring[]
Filter by expense classification. Values:
capex, opexstring[]
Filter by file UUID
string[]
Filter by supplier UUID
string[]
Filter by currency unit UUID
string
Filter records created on or after this date
string
Filter records created on or before this date
string
Filter by CO2e calculation status
Body Parameters
string
required
Hash from the list endpoint response. Must match the current filter set.
Response
string[]
UUIDs of successfully deleted purchases
object[]
Failed deletions with reason
Example
# Step 1: Get filter_hash from list
RESPONSE=$(curl -s "https://api.dcycle.io/v1/purchases?expense_type[]=opex&purchase_date_to=2024-12-31" \
-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/purchases/bulk-delete-by-filters?expense_type[]=opex&purchase_date_to=2024-12-31" \
-H "x-api-key: ${DCYCLE_API_KEY}" \
-H "x-organization-id: ${DCYCLE_ORG_ID}" \
-H "Content-Type: application/json" \
-d "{\"filter_hash\": \"${FILTER_HASH}\"}"
import requests
import os
headers = {
"x-api-key": os.getenv("DCYCLE_API_KEY"),
"x-organization-id": os.getenv("DCYCLE_ORG_ID"),
}
filters = {"expense_type[]": "opex", "purchase_date_to": "2024-12-31"}
# Step 1: Get filter_hash from list
list_resp = requests.get(
"https://api.dcycle.io/v1/purchases",
headers=headers,
params=filters,
)
filter_hash = list_resp.json()["filter_hash"]
# Step 2: Bulk delete with the same filters
delete_resp = requests.post(
"https://api.dcycle.io/v1/purchases/bulk-delete-by-filters",
headers={**headers, "Content-Type": "application/json"},
params=filters,
json={"filter_hash": filter_hash},
)
result = delete_resp.json()
print(f"Deleted: {len(result['deleted'])} | Failed: {len(result['failed'])}")
const axios = require('axios');
const headers = {
'x-api-key': process.env.DCYCLE_API_KEY,
'x-organization-id': process.env.DCYCLE_ORG_ID,
};
const filters = { 'expense_type[]': 'opex', purchase_date_to: '2024-12-31' };
// Step 1: Get filter_hash from list
const listResp = await axios.get('https://api.dcycle.io/v1/purchases', {
headers, params: filters,
});
const filterHash = listResp.data.filter_hash;
// Step 2: Bulk delete with the same filters
const deleteResp = await axios.post(
'https://api.dcycle.io/v1/purchases/bulk-delete-by-filters',
{ filter_hash: filterHash },
{ headers: { ...headers, 'Content-Type': 'application/json' }, params: filters },
);
console.log(`Deleted: ${deleteResp.data.deleted.length}`);
Successful Response
{
"deleted": [
"a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"b2c3d4e5-f6a7-8901-bcde-f12345678901"
],
"failed": []
}
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: Thefilter_hash doesn’t match the current filters — they changed since the list was loaded
{
"detail": "Filter hash mismatch. The filters have changed since the list was loaded. Please refresh and try again."
}
Related Endpoints
Bulk Delete
Delete specific purchases by ID
List Purchases
Browse purchases and get filter_hash
Was this page helpful?