Get Purchase Version History
const options = {
method: 'GET',
headers: {'x-api-key': '<x-api-key>', 'x-organization-id': '<x-organization-id>'}
};
fetch('https://api.dcycle.io/v1/purchases/{purchase_id}/versions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.dcycle.io/v1/purchases/{purchase_id}/versions"
headers = {
"x-api-key": "<x-api-key>",
"x-organization-id": "<x-organization-id>"
}
response = requests.get(url, headers=headers)
print(response.text)curl --request GET \
--url https://api.dcycle.io/v1/purchases/{purchase_id}/versions \
--header 'x-api-key: <x-api-key>' \
--header 'x-organization-id: <x-organization-id>'{
"items": {},
"total": 123,
"page": 123,
"size": 123
}Get Purchase Version History
Get the change history of a purchase record
GET
/
v1
/
purchases
/
{purchase_id}
/
versions
Get Purchase Version History
const options = {
method: 'GET',
headers: {'x-api-key': '<x-api-key>', 'x-organization-id': '<x-organization-id>'}
};
fetch('https://api.dcycle.io/v1/purchases/{purchase_id}/versions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.dcycle.io/v1/purchases/{purchase_id}/versions"
headers = {
"x-api-key": "<x-api-key>",
"x-organization-id": "<x-organization-id>"
}
response = requests.get(url, headers=headers)
print(response.text)curl --request GET \
--url https://api.dcycle.io/v1/purchases/{purchase_id}/versions \
--header 'x-api-key: <x-api-key>' \
--header 'x-organization-id: <x-organization-id>'{
"items": {},
"total": 123,
"page": 123,
"size": 123
}← Purchases API
Returns a paginated list of all changes made to a purchase over time, including who made the change, when, and which fields were modified.
The history reports the product (
description, product_name), purchase_date, expense_type, the spend
(quantity, unit_id, price, currency), the physical quantity (non_currency_quantity, non_currency_unit_id),
recycled, the supplier (supplier_id, business_name, supplier_country), organization_id,
attachment_file_name and the emission factor. A supplier_id change gives the suppliers’ ids and is followed by a
supplier change with their names: suppliers of the purchase’s organization or of its group. Any other supplier,
and one that no longer exists, is given by its id.
Request
Headers
Path Parameters
Query Parameters
Response
Version entries:
| Field | Type | Description |
|---|---|---|
index | integer | Version number (0 = creation) |
changeset | object | Map of field names to [old_value, new_value] pairs |
user_id | string | null | UUID of the user who made the change |
created_at | string | ISO 8601 timestamp |
Example
curl -X GET "https://api.dcycle.io/v1/purchases/${PURCHASE_ID}/versions" \
-H "x-api-key: ${DCYCLE_API_KEY}" \
-H "x-organization-id: ${DCYCLE_ORG_ID}"
import requests
import os
headers = {
"x-api-key": os.getenv("DCYCLE_API_KEY"),
"x-organization-id": os.getenv("DCYCLE_ORG_ID"),
}
purchase_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
response = requests.get(
f"https://api.dcycle.io/v1/purchases/{purchase_id}/versions",
headers=headers,
)
data = response.json()
print(f"{data['total']} versions")
for v in data["items"]:
fields = ", ".join(v["changeset"].keys()) if v["changeset"] else "created"
print(f" v{v['index']}: {fields} ({v['created_at']})")
const axios = require('axios');
const headers = {
'x-api-key': process.env.DCYCLE_API_KEY,
'x-organization-id': process.env.DCYCLE_ORG_ID,
};
const purchaseId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
axios.get(`https://api.dcycle.io/v1/purchases/${purchaseId}/versions`, { headers })
.then(response => {
const { items, total } = response.data;
console.log(`${total} versions`);
items.forEach(v => {
const fields = Object.keys(v.changeset).join(', ') || 'created';
console.log(` v${v.index}: ${fields}`);
});
});
Successful Response
{
"items": [
{
"index": 0,
"changeset": {},
"user_id": "user-uuid-here",
"created_at": "2025-03-10T14:22:00Z"
},
{
"index": 1,
"changeset": {
"quantity": [100.0, 150.0],
"description": ["Office supplies", "Office supplies Q1"]
},
"user_id": "user-uuid-here",
"created_at": "2025-03-15T09:10:00Z"
}
],
"total": 2,
"page": 1,
"size": 50
}
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"}
404 Not Found
Cause: The purchase does not exist or belongs to another organization{"detail": "Purchase not found"}
Related Endpoints
Get Purchase
View current purchase details
Update Purchase
Modify a purchase record
Was this page helpful?