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

fetch('https://api.dcycle.io/v1/purchases/bulk-delete', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
{
  "deleted": [
    "<string>"
  ],
  "failed": [
    {}
  ]
}

Bulk Delete

Delete multiple purchases by their IDs. All purchases must belong to the requesting organization. Related emission records (total_impacts) are automatically deleted to maintain referential integrity. Returns detailed results for each ID, allowing you to handle partial failures gracefully.

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

Body Parameters

purchase_ids
string[]
required
Array of purchase UUIDs to delete (1–100,000 per request)

Response

deleted
string[]
UUIDs of successfully deleted purchases
failed
object[]
Failed deletions with reason:
FieldTypeDescription
idstringThe purchase UUID that failed
reasonstringWhy the deletion failed

Example

curl -X POST "https://api.dcycle.io/v1/purchases/bulk-delete" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d '{
    "purchase_ids": [
      "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "b2c3d4e5-f6a7-8901-bcde-f12345678901"
    ]
  }'

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

422 Validation Error

Cause: Empty array or more than 100,000 IDs
{
  "detail": [
    {
      "loc": ["body", "purchase_ids"],
      "msg": "ensure this value has at least 1 items",
      "type": "value_error.list.min_items"
    }
  ]
}

Bulk Delete by Filters

Delete all purchases matching filter criteria

List Purchases

Browse and filter purchases