> ## 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 business travel record

# Version History

Returns a paginated list of all changes made to a business travel record, including what changed, when, and by whom. Useful for auditing data modifications.

## 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="business_travel_id" type="string" required>
  UUID of the business travel

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

### Query Parameters

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

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

## Response

<ResponseField name="items" type="array[object]">
  Version entries with change details

  <Expandable title="version object fields">
    <ResponseField name="items[].transaction_id" type="integer">
      Internal transaction identifier
    </ResponseField>

    <ResponseField name="items[].operation_type" type="string">
      The type of operation: `CREATE`, `UPDATE`, or `DELETE`
    </ResponseField>

    <ResponseField name="items[].issued_at" type="datetime | null">
      When the change was made (ISO 8601)
    </ResponseField>

    <ResponseField name="items[].user_id" type="string | null">
      UUID of the user who made the change
    </ResponseField>

    <ResponseField name="items[].user_first_name" type="string | null">
      First name of the user who made the change
    </ResponseField>

    <ResponseField name="items[].user_last_name" type="string | null">
      Last name of the user who made the change
    </ResponseField>

    <ResponseField name="items[].changes" type="array[object]">
      List of field-level changes in this version

      <Expandable title="change object fields">
        <ResponseField name="field" type="string">
          The field that changed
        </ResponseField>

        <ResponseField name="old_value" type="any">
          Previous value (null for CREATE operations)
        </ResponseField>

        <ResponseField name="new_value" type="any">
          New value (null for DELETE operations)
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</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/business-travels/${BUSINESS_TRAVEL_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"),
  }

  bt_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"

  response = requests.get(
      f"https://api.dcycle.io/v1/business-travels/{bt_id}/versions",
      headers=headers,
  )

  data = response.json()
  print(f"{data['total']} versions (page {data['page']}/{data['pages']})")
  for v in data["items"]:
      user = f"{v['user_first_name']} {v['user_last_name']}" if v.get("user_first_name") else "System"
      print(f"  [{v['operation_type']}] at {v['issued_at']} by {user}")
      for c in v["changes"]:
          print(f"    {c['field']}: {c['old_value']} → {c['new_value']}")
  ```

  ```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 btId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';

  axios.get(`https://api.dcycle.io/v1/business-travels/${btId}/versions`, { headers })
  .then(({ data }) => {
    console.log(`${data.total} versions (page ${data.page}/${data.pages})`);
    data.items.forEach(v => {
      const user = v.user_first_name ? `${v.user_first_name} ${v.user_last_name}` : 'System';
      console.log(`  [${v.operation_type}] at ${v.issued_at} by ${user}`);
      v.changes.forEach(c => console.log(`    ${c.field}: ${c.old_value} → ${c.new_value}`));
    });
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "items": [
    {
      "transaction_id": 12345,
      "operation_type": "UPDATE",
      "issued_at": "2024-06-15T10:30:00Z",
      "user_id": "d4e5f6a7-b8c9-0123-defg-456789012345",
      "user_first_name": "María",
      "user_last_name": "García",
      "changes": [
        {
          "field": "distance",
          "old_value": 500.0,
          "new_value": 620.0
        },
        {
          "field": "transport_type",
          "old_value": "car",
          "new_value": "train"
        }
      ]
    },
    {
      "transaction_id": 12300,
      "operation_type": "CREATE",
      "issued_at": "2024-06-01T09:00:00Z",
      "user_id": "d4e5f6a7-b8c9-0123-defg-456789012345",
      "user_first_name": "María",
      "user_last_name": "García",
      "changes": []
    }
  ],
  "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:** Business travel not found or doesn't belong to your organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "BusinessTravel with id=UUID('...') not found", "code": "BUSINESS_TRAVEL_NOT_FOUND"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Business Travel" icon="magnifying-glass" href="/api-reference/business-travels/get">
    View current business travel details
  </Card>

  <Card title="Update" icon="pencil" href="/api-reference/business-travels/update">
    Modify a business travel
  </Card>
</CardGroup>
