> ## Documentation Index
> Fetch the complete documentation index at: https://code.dcycle.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Purchase

> Retrieve a specific purchase by its ID

# Get Purchase

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

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### Path Parameters

<ParamField path="purchase_id" type="string" required>
  The unique identifier (UUID) of the purchase to retrieve

  **Example:** `550e8400-e29b-41d4-a716-446655440000`
</ParamField>

## Response

<ResponseField name="id" type="string">
  Unique identifier (UUID)
</ResponseField>

<ResponseField name="organization_id" type="string">
  Organization UUID
</ResponseField>

<ResponseField name="product_name" type="string | null">
  Name of the product or service
</ResponseField>

<ResponseField name="description" type="string | null">
  Optional description
</ResponseField>

<ResponseField name="sector" type="string | null">
  Economic sector
</ResponseField>

<ResponseField name="country" type="string | null">
  2-letter ISO country code
</ResponseField>

<ResponseField name="quantity" type="number | null">
  Purchase amount
</ResponseField>

<ResponseField name="unit_id" type="string | null">
  Unit of measurement
</ResponseField>

<ResponseField name="purchase_date" type="date | null">
  Date of purchase
</ResponseField>

<ResponseField name="purchase_type" type="string | null">
  Calculation method: `spend_based` or `supplier_specific`
</ResponseField>

<ResponseField name="expense_type" type="string">
  Classification: `capex` or `opex`
</ResponseField>

<ResponseField name="status" type="string | null">
  Purchase status
</ResponseField>

<ResponseField name="recycled" type="number | null">
  Recycled content percentage (0-1)
</ResponseField>

<ResponseField name="supplier_id" type="string | null">
  Supplier identifier
</ResponseField>

<ResponseField name="custom_emission_factor_id" type="string | null">
  Custom emission factor UUID
</ResponseField>

<ResponseField name="file_id" type="string | null">
  Linked file UUID
</ResponseField>

<ResponseField name="file_name" type="string | null">
  Linked file name
</ResponseField>

<ResponseField name="file_url" type="string | null">
  Linked file download URL
</ResponseField>

<ResponseField name="co2e" type="number | null">
  Calculated CO2 equivalent emissions (kg)
</ResponseField>

<ResponseField name="frequency" type="string | null">
  Purchase frequency
</ResponseField>

<ResponseField name="exchange_rate_to_eur" type="number | null">
  Exchange rate used to convert the purchase amount to EUR
</ResponseField>

<ResponseField name="exchange_rate_date" type="date | null">
  Date used for the exchange rate lookup
</ResponseField>

<ResponseField name="custom_emission_group" type="object | null">
  Custom emission group applied to this purchase

  | Field         | Type           | Description       |
  | ------------- | -------------- | ----------------- |
  | `id`          | string         | Group UUID        |
  | `name`        | string \| null | Group name        |
  | `category`    | string \| null | Group category    |
  | `description` | string \| null | Group description |
</ResponseField>

<ResponseField name="last_purchase_timestamp" type="datetime | null">
  Timestamp of the most recent purchase in a recurring series
</ResponseField>

<ResponseField name="supplier" type="object | null">
  Supplier details

  | Field           | Type            | Description                     |
  | --------------- | --------------- | ------------------------------- |
  | `id`            | string          | Supplier UUID                   |
  | `business_name` | string \| null  | Supplier business name          |
  | `country`       | string \| null  | Supplier country code           |
  | `enabled`       | boolean \| null | Whether the supplier is enabled |
</ResponseField>

<ResponseField name="unit" type="object | null">
  Unit of measurement details

  | Field  | Type   | Description                             |
  | ------ | ------ | --------------------------------------- |
  | `id`   | string | Unit UUID                               |
  | `name` | string | Unit name (e.g. `EUR`, `kilogram_(kg)`) |
  | `type` | string | Unit category                           |
</ResponseField>

<ResponseField name="uploaded_by" type="string | null">
  UUID of the user who created this record
</ResponseField>

<ResponseField name="uploaded_by_user" type="object | null">
  User who created this record

  | Field             | Type           | Description       |
  | ----------------- | -------------- | ----------------- |
  | `id`              | string         | User UUID         |
  | `first_name`      | string         | First name        |
  | `last_name`       | string         | Last name         |
  | `email`           | string         | Email address     |
  | `profile_img_url` | string \| null | Profile image URL |
</ResponseField>

<ResponseField name="created_at" type="datetime">
  Timestamp when the purchase was created
</ResponseField>

<ResponseField name="updated_at" type="datetime | null">
  Timestamp when the purchase was last updated
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  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}"
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  api_key = os.getenv("DCYCLE_API_KEY")
  org_id = os.getenv("DCYCLE_ORG_ID")

  headers = {
      "x-api-key": api_key,
      "x-organization-id": org_id
  }

  purchase_id = "550e8400-e29b-41d4-a716-446655440000"

  response = requests.get(
      f"https://api.dcycle.io/v1/purchases/{purchase_id}",
      headers=headers
  )

  purchase = response.json()
  print(f"Product: {purchase['product_name']}")
  print(f"Quantity: {purchase['quantity']} {purchase['unit_id']}")
  print(f"CO2e: {purchase['co2e']} kg")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const apiKey = process.env.DCYCLE_API_KEY;
  const orgId = process.env.DCYCLE_ORG_ID;

  const headers = {
    'x-api-key': apiKey,
    'x-organization-id': orgId
  };

  const purchaseId = '550e8400-e29b-41d4-a716-446655440000';

  axios.get(
    `https://api.dcycle.io/v1/purchases/${purchaseId}`,
    { headers }
  )
  .then(response => {
    const purchase = response.data;
    console.log(`Product: ${purchase.product_name}`);
    console.log(`Quantity: ${purchase.quantity} ${purchase.unit_id}`);
    console.log(`CO2e: ${purchase.co2e} kg`);
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "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",
  "exchange_rate_to_eur": 1.0,
  "exchange_rate_date": "2024-03-15",
  "custom_emission_group": null,
  "last_purchase_timestamp": null,
  "supplier": {
    "id": "supplier-123",
    "business_name": "Office Depot",
    "country": "ES",
    "enabled": true
  },
  "unit": { "id": "unit-uuid", "name": "EUR", "type": "currency" },
  "uploaded_by": null,
  "uploaded_by_user": null,
  "created_at": "2024-03-15T10:30:00Z",
  "updated_at": "2024-03-15T10:30:00Z"
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "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

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "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

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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}")
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Purchases" icon="list" href="/api-reference/purchases/list">
    Retrieve all purchases with filtering
  </Card>

  <Card title="Update Purchase" icon="pencil" href="/api-reference/purchases/update">
    Modify purchase details
  </Card>

  <Card title="Delete Purchase" icon="trash" href="/api-reference/purchases/delete">
    Remove a purchase
  </Card>

  <Card title="Create Purchase" icon="plus" href="/api-reference/purchases/create">
    Add a new purchase
  </Card>
</CardGroup>
