> ## 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.

# Version History

> Get the change history of a purchase record

# Version History

Returns a paginated list of all changes made to a purchase over time, including who made the change, when, and which fields were modified.

## 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>
  UUID of the purchase
</ParamField>

### Query Parameters

<ParamField query="page" type="integer" default="1">
  Page number (1-based)
</ParamField>

<ParamField query="size" type="integer" default="50">
  Items per page (max 100)
</ParamField>

## Response

<ResponseField name="items" type="array[object]">
  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                                   |
</ResponseField>

<ResponseField name="total" type="integer">
  Total number of versions
</ResponseField>

<ResponseField name="page" type="integer">
  Current page number
</ResponseField>

<ResponseField name="size" type="integer">
  Page size
</ResponseField>

## Example

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

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

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  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}`);
    });
  });
  ```
</CodeGroup>

### Successful Response

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

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

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

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Purchase not found"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Purchase" icon="magnifying-glass" href="/api-reference/purchases/get">
    View current purchase details
  </Card>

  <Card title="Update Purchase" icon="pen" href="/api-reference/purchases/update">
    Modify a purchase record
  </Card>
</CardGroup>
