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

# Vehicle Versions

> Retrieve the version history of a vehicle

# Vehicle Versions

Retrieve a paginated audit trail of all changes made to a vehicle over time, including who made each 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="vehicle_id" type="string" required>
  UUID of the vehicle
</ParamField>

### Query Parameters

<ParamField query="page" type="integer" default="1">
  Page number
</ParamField>

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

## Response

<ResponseField name="items" type="array[object]">
  List of version records
</ResponseField>

<ResponseField name="items[].transaction_id" type="integer">
  Unique transaction identifier
</ResponseField>

<ResponseField name="items[].end_transaction_id" type="integer | null">
  End transaction ID (null for current version)
</ResponseField>

<ResponseField name="items[].operation_type" type="integer">
  Operation: `0` = create, `1` = update, `2` = delete
</ResponseField>

<ResponseField name="items[].issued_at" type="string">
  ISO 8601 timestamp of the change
</ResponseField>

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

<ResponseField name="items[].changeset" type="object">
  Map of changed fields with `[old_value, new_value]` pairs
</ResponseField>

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

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

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl "https://api.dcycle.io/v1/vehicles/${VEHICLE_ID}/versions?page=1&size=10" \
    -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

  response = requests.get(
      f"https://api.dcycle.io/v1/vehicles/{os.getenv('VEHICLE_ID')}/versions",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
      params={"page": 1, "size": 10},
  )

  data = response.json()
  for version in data["items"]:
      print(f"{version['issued_at']} by {version['user_name']}: {version['changeset']}")
  ```

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

  const response = await axios.get(
    `https://api.dcycle.io/v1/vehicles/${process.env.VEHICLE_ID}/versions`,
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
      },
      params: { page: 1, size: 10 },
    }
  );

  response.data.items.forEach(v =>
    console.log(`${v.issued_at} by ${v.user_name}: ${JSON.stringify(v.changeset)}`)
  );
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "items": [
    {
      "transaction_id": 98765,
      "end_transaction_id": null,
      "operation_type": 1,
      "issued_at": "2025-03-10T14:30:00Z",
      "user_name": "Ana Garcia",
      "changeset": {
        "name": ["Fleet Van #12", "Company Van #12"],
        "status": ["error", "active"]
      }
    },
    {
      "transaction_id": 87654,
      "end_transaction_id": 98765,
      "operation_type": 0,
      "issued_at": "2024-06-15T10:30:00Z",
      "user_name": "Carlos Lopez",
      "changeset": {}
    }
  ],
  "total": 2,
  "page": 1,
  "size": 10
}
```

## 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 vehicle does not exist or belongs to another organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Not Found"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Vehicle" icon="car" href="/api-reference/vehicles/get">
    View current vehicle details
  </Card>

  <Card title="Update Vehicle" icon="pen" href="/api-reference/vehicles/update">
    Modify vehicle details
  </Card>
</CardGroup>
