> ## 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 Transport Route Version History

> Retrieve the full audit trail of changes made to a transport route, with field-level diffs and user attribution

# Get Transport Route Version History

Returns a paginated list of every change ever made to a transport route — who made it, when, and which fields were affected. Each entry covers one database transaction and includes a `changes` array that shows the before/after value for each tracked field.

Tracked fields: `name`, `quantity`, `unit_id`, `start_date`, `transport_direction`.

## 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="transport_route_id" type="string" required>
  The unique identifier (UUID) of the transport route

  **Example:** `010ed3b6-b513-40f3-b9fe-0f0a338d9274`
</ParamField>

### Query Parameters

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

<ParamField query="size" type="integer" default="50">
  Number of version entries per page
</ParamField>

## Response

<ResponseField name="items" type="array">
  List of version entries for the requested page. See [Version Entry Fields](#version-entry-fields) below.
</ResponseField>

<ResponseField name="total" type="integer">
  Total number of version entries across all pages
</ResponseField>

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

<ResponseField name="size" type="integer">
  Number of items per page
</ResponseField>

### Version Entry Fields

<ResponseField name="items[].transaction_id" type="integer">
  Internal database transaction ID. Versions are returned newest-first (descending `transaction_id`).
</ResponseField>

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

<ResponseField name="items[].issued_at" type="datetime | null">
  ISO 8601 timestamp of when the change was committed. `null` for very old records pre-dating audit logging.
</ResponseField>

<ResponseField name="items[].user_id" type="string | null">
  ID of the user who made the change. `null` for system-triggered changes.
</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">
  Field-level diff for this version entry.

  <Expandable title="changes[] fields">
    <ResponseField name="changes[].field" type="string">
      Name of the field that changed, e.g. `name`, `quantity`, `transport_direction`
    </ResponseField>

    <ResponseField name="changes[].old_value" type="any | null">
      Value of the field before the change. `null` for `CREATE` operations.
    </ResponseField>

    <ResponseField name="changes[].new_value" type="any | null">
      Value of the field after the change. `null` for `DELETE` operations.
    </ResponseField>
  </Expandable>
</ResponseField>

<Note>
  For `CREATE` operations, `old_value` is always `null` and `new_value` contains the initial value of each tracked field. For `UPDATE` operations, only fields that actually changed are included in `changes`. For `DELETE` operations, `changes` is an empty array.
</Note>

## Example

<CodeGroup>
  ```bash cURL (API Key) theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X GET "https://api.dcycle.io/v1/transports/010ed3b6-b513-40f3-b9fe-0f0a338d9274/versions?page=1&size=50" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}"
  ```

  ```bash cURL (JWT) theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X GET "https://api.dcycle.io/v1/transports/010ed3b6-b513-40f3-b9fe-0f0a338d9274/versions?page=1&size=50" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}"
  ```

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

  route_id = "010ed3b6-b513-40f3-b9fe-0f0a338d9274"

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

  data = response.json()
  print(f"Total versions: {data['total']}")
  for version in data["items"]:
      print(
          f"  [{version['operation_type']}] {version['issued_at']} "
          f"by {version['user_first_name']} {version['user_last_name']}"
      )
      for change in version["changes"]:
          print(f"    {change['field']}: {change['old_value']} → {change['new_value']}")
  ```

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

  const routeId = '010ed3b6-b513-40f3-b9fe-0f0a338d9274';

  axios.get(`https://api.dcycle.io/v1/transports/${routeId}/versions`, {
    headers: {
      'x-api-key': process.env.DCYCLE_API_KEY,
      'x-organization-id': process.env.DCYCLE_ORG_ID,
    },
    params: { page: 1, size: 50 },
  })
  .then(({ data }) => {
    console.log(`Total versions: ${data.total}`);
    data.items.forEach(version => {
      console.log(
        `[${version.operation_type}] ${version.issued_at} ` +
        `by ${version.user_first_name} ${version.user_last_name}`
      );
      version.changes.forEach(c => {
        console.log(`  ${c.field}: ${c.old_value} → ${c.new_value}`);
      });
    });
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "items": [
    {
      "transaction_id": 48291,
      "operation_type": "UPDATE",
      "issued_at": "2024-06-20T11:45:00Z",
      "user_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
      "user_first_name": "Maria",
      "user_last_name": "Garcia",
      "changes": [
        {
          "field": "quantity",
          "old_value": "1000",
          "new_value": "1500"
        },
        {
          "field": "transport_direction",
          "old_value": "upstream",
          "new_value": "downstream"
        }
      ]
    },
    {
      "transaction_id": 47103,
      "operation_type": "CREATE",
      "issued_at": "2024-06-10T09:00:00Z",
      "user_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
      "user_first_name": "Maria",
      "user_last_name": "Garcia",
      "changes": [
        {
          "field": "name",
          "old_value": null,
          "new_value": "Madrid to Syria Shipment"
        },
        {
          "field": "quantity",
          "old_value": null,
          "new_value": "1000"
        },
        {
          "field": "transport_direction",
          "old_value": null,
          "new_value": "upstream"
        }
      ]
    }
  ],
  "total": 2,
  "page": 1,
  "size": 50
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key / JWT token

```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:** Route ID does not exist or belongs to a different organization

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

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Transport Route" icon="eye" href="/api-reference/transport/get">
    Retrieve the current state of a transport route
  </Card>

  <Card title="Update Transport Route" icon="pencil" href="/api-reference/transport/update">
    Modify a transport route and its sections
  </Card>

  <Card title="List Transport Routes" icon="list" href="/api-reference/transport/list">
    Retrieve all transport routes with filtering and pagination
  </Card>

  <Card title="Transport Overview" icon="book" href="/api-reference/transport/overview">
    Full data model and distance calculation reference
  </Card>
</CardGroup>
