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

# Document Versioning

Trade partners sometimes send updated versions of a document they already sent — for example, a revised order with a changed quantity or an amended invoice. Procuros detects these and links the old and new versions together automatically.

Every transaction returned by the API includes three fields that tell you where it sits in that version chain:

| Field                             | Type           | Description                                                                                          |
| --------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------- |
| `isLatestVersion`                 | `boolean`      | `true` if no newer version exists. `false` if this document has been superseded.                     |
| `replacesProcurosTransactionId`   | `uuid \| null` | The ID of the older transaction this one replaces. `null` if this is the original document.          |
| `replacedByProcurosTransactionId` | `uuid \| null` | The ID of the newer transaction that replaced this one. `null` if this is still the current version. |

## Recommended Handling

**Always check `isLatestVersion` before importing a document into your system.** If the value is `false`, a newer version of the document is already available and the one you are looking at should be skipped or voided.

```php php theme={null}
foreach ($body->items as $transaction) {
    if (!$transaction->isLatestVersion) {
        // A newer version exists — skip or void this document
        continue;
    }

    // Safe to import
    importTransaction($transaction);
}
```

If `isLatestVersion` is `false` and the document was already imported, you can use `replacedByProcurosTransactionId` to identify the newer version. The newer version will also appear as a separate pending transaction on `GET /v2/transactions`, so no additional API call is needed — simply skip the outdated document and process the newer one when it comes up.

```php php theme={null}
if (!$transaction->isLatestVersion) {
    // A newer version will arrive (or has already arrived) as its own pending transaction.
    // Skip this outdated document, or void it if it was already imported.
    continue;
}
```

### Marking outdated versions as processed

When you mark a transaction as processed, Procuros records that you have acknowledged it. If a transaction in your queue turns out to have `isLatestVersion: false`, you do not need to take any special action — Procuros automatically removes outdated versions from the pending queue before they are returned to you. You will only ever need to mark the latest version as processed.

## Version Chain Example

Given three versions of the same order:

| `procurosTransactionId` | `replacesProcurosTransactionId` | `replacedByProcurosTransactionId` | `isLatestVersion` |
| ----------------------- | ------------------------------- | --------------------------------- | ----------------- |
| `aaa-111`               | `null`                          | `bbb-222`                         | `false`           |
| `bbb-222`               | `aaa-111`                       | `ccc-333`                         | `false`           |
| `ccc-333`               | `bbb-222`                       | `null`                            | `true`            |

Only `ccc-333` should be imported. The earlier versions can be safely skipped or voided.

<Info>
  When polling via `GET /v2/transactions` (pending transactions), outdated versions are removed from the queue automatically as soon as a newer version is detected. `isLatestVersion` will always be `true` for transactions returned by this endpoint.
</Info>
