Skip to main content
GET
https://api.dcycle.io
/
v1
/
purchases
/
{purchase_id}
Get Purchase
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}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
{
  "id": "<string>",
  "organization_id": "<string>",
  "product_name": {},
  "description": {},
  "sector": {},
  "country": {},
  "quantity": {},
  "unit_id": {},
  "purchase_date": {},
  "purchase_type": {},
  "expense_type": {},
  "status": {},
  "recycled": {},
  "supplier_id": {},
  "custom_emission_factor_id": {},
  "file_id": {},
  "file_name": {},
  "file_url": {},
  "co2e": {},
  "frequency": {},
  "created_at": {},
  "updated_at": {}
}

Get Purchase

Retrieve detailed information about a specific purchase using its unique identifier.

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

Path Parameters

purchase_id
string
required
The unique identifier (UUID) of the purchase to retrieveExample: 550e8400-e29b-41d4-a716-446655440000

Response

id
string
Unique identifier (UUID)
organization_id
string
Organization UUID
product_name
string | null
Name of the product or service
description
string | null
Optional description
sector
string | null
Economic sector
country
string | null
2-letter ISO country code
quantity
number | null
Purchase amount
unit_id
string | null
Unit of measurement
purchase_date
date | null
Date of purchase
purchase_type
string | null
Calculation method: spend_based or supplier_specific
expense_type
string | null
Classification: capex or opex
status
string | null
Purchase status
recycled
number | null
Recycled content percentage (0-1)
supplier_id
string | null
Supplier identifier
custom_emission_factor_id
string | null
Custom emission factor UUID
file_id
string | null
Linked file UUID
file_name
string | null
Linked file name
file_url
string | null
Linked file download URL
co2e
number | null
Calculated CO2 equivalent emissions (kg)
frequency
string | null
Purchase frequency
created_at
datetime | null
Timestamp when the purchase was created
updated_at
datetime | null
Timestamp when the purchase was last updated

Example

curl -X GET "https://api.dcycle.io/v1/purchases/550e8400-e29b-41d4-a716-446655440000" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}"

Successful Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "organization_id": "a8315ef3-dd50-43f8-b7ce-d839e68d51fa",
  "product_name": "Office Supplies",
  "description": "Q1 2024 office supplies order",
  "sector": "Manufacturing",
  "country": "ES",
  "quantity": 1500.00,
  "unit_id": "EUR",
  "purchase_date": "2024-03-15",
  "purchase_type": "spend_based",
  "expense_type": "opex",
  "status": "active",
  "recycled": 0.25,
  "supplier_id": "supplier-123",
  "custom_emission_factor_id": null,
  "file_id": "660e8400-e29b-41d4-a716-446655440000",
  "file_name": "invoice_q1_2024.pdf",
  "file_url": "https://storage.dcycle.io/...",
  "co2e": 245.5,
  "frequency": "once",
  "created_at": "2024-03-15T10:30:00Z",
  "updated_at": "2024-03-15T10:30:00Z"
}

Common Errors

401 Unauthorized

Cause: Missing or invalid API key
{
  "detail": "Invalid API key",
  "code": "INVALID_API_KEY"
}
Solution: Verify your API key is valid and active.

404 Not Found

Cause: Purchase not found or doesn’t belong to your organization
{
  "detail": "Purchase not found",
  "code": "PURCHASE_NOT_FOUND"
}
Solution: Verify the purchase ID exists and belongs to the organization specified in the header.

422 Validation Error

Cause: Invalid purchase ID format
{
  "detail": [
    {
      "loc": ["path", "purchase_id"],
      "msg": "value is not a valid uuid",
      "type": "type_error.uuid"
    }
  ]
}
Solution: Ensure the purchase ID is a valid UUID format.

Use Cases

Verify Purchase Details Before Update

def get_and_verify_purchase(purchase_id):
    """Get purchase and verify it can be updated"""
    response = requests.get(
        f"https://api.dcycle.io/v1/purchases/{purchase_id}",
        headers=headers
    )

    if response.status_code == 404:
        raise ValueError("Purchase not found")

    purchase = response.json()

    if purchase["status"] == "in_progress":
        raise ValueError("Cannot modify purchase while in progress")

    return purchase

# Verify before updating
purchase = get_and_verify_purchase("550e8400-e29b-41d4-a716-446655440000")
print(f"Current CO2e: {purchase['co2e']} kg")

Check Calculation Status

def check_purchase_calculation(purchase_id):
    """Check if purchase emissions have been calculated"""
    response = requests.get(
        f"https://api.dcycle.io/v1/purchases/{purchase_id}",
        headers=headers
    )
    purchase = response.json()

    if purchase["co2e"] is None:
        return "pending"
    elif purchase["status"] == "error":
        return "error"
    else:
        return "calculated"

status = check_purchase_calculation("550e8400-e29b-41d4-a716-446655440000")
print(f"Calculation status: {status}")