# Audit trail API

> GET /api/audit (the audit trail's records, newest first, paged with the X-Audit-Next-Before cursor and filtered by category, action, user, resource, origin and time) and GET /api/audit/verify (the chain check), the 403 NO_AUDIT_TRAIL, 503 AUDIT_NOT_WRITTEN, 400 and 500 answers, the trail's state (X-Audit-Trail-Mode, audit_trail in /api/system/health, /api/system/info and /api/licence), and the audit trail's own record actions (AUDIT_TRAIL_STARTED, AUDIT_TRAIL_RESUMED, AUDIT_STORAGE_WARNING, LEDGER_TIP_MISMATCH, LEDGER_COMMIT_UNCONFIRMED, LEDGER_FILE_SET_ASIDE, LEDGER_FILE_REPAIRED, AUDIT_TRAIL_RESTORED).

Product: eaxScada · Type: Reference · Editions: Starter, Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/reference/audit-trail-api/
Verified against commit e9926e8.

The routes that read the audit trail, the Operations audit of **Security** (`audit.duckdb`, Starter, Pro and Enterprise). The trail itself: [Security and 21 CFR Part 11](/docs/platform/explanation/security-and-part-11/#2-sha-256-chained-audit-trail-starter-pro-enterprise).

## Who may call them

- **A signed-in user**, in a session; `401` without one. Records about a tag (a write with its old and new value, a refused write, an AI setpoint, a recipe setpoint) are left out for a caller who may not read that tag; every other record is returned as it is ([tag read rights](/docs/platform/explanation/security-and-part-11/#53-default-topic-permissions-of-a-new-install)). In the Studio, the Security workspace's **Operations audit** tab is shown to Administrator, Compliance_Auditor, Lead_Engineer and Process_Supervisor.
- **Never over remote access** (eaxCloud remote sessions).
- **Starter, Pro and Enterprise.** A server without an audit trail (the Free edition, a build without DuckDB) answers `403` ([below](#403-no_audit_trail)). A Free server that holds a trail from a paid period answers both routes from it, read-only.
- **`X-Audit-Trail-Mode`**, on the answers of both routes once the caller is signed in (the `403` included): the trail's mode, `recording`, `down`, `read_only` or `none` ([The trail's state](#the-trails-state)). The Operations audit shows its note above the grid from it.

| Method | Path | What it does |
|---|---|---|
| GET | `/api/audit` | A page of records, newest first. |
| GET | `/api/audit/verify` | Checks the whole chain. |

## GET /api/audit

| Parameter | Value | Default |
|---|---|---|
| `limit` | Records per page, a whole number; `0` for every record | `100` |
| `before` | The cursor: the `X-Audit-Next-Before` header of the previous page. Only records before that place in the trail. | the newest record |
| `category` | Exact category, for example `ALARM`, `DEPLOY`, `SYSTEM`, `SECURITY` | every category |
| `action` | Exact action, for example `MANUAL_OVERRIDE` | every action |
| `user` | Exact user id of the record (`user_id`) | every user |
| `resource` | Exact resource, or a prefix ending in `*` (`Plant/Line1/*`) | every resource |
| `origin` | Exact origin: the server run that wrote the record ([How verification works](/docs/platform/explanation/security-and-part-11/#how-verification-works)) | every origin |
| `from`, `to` | A time, inclusive: RFC 3339 (`2026-11-11T08:00:00Z`) or Unix milliseconds | open |

Filters combine (all must match). Every value is passed to the database as a parameter, never as query text.

**The answer** is a JSON array of records, newest first, the same as before this release. When there are more records, the header `X-Audit-Next-Before` carries the cursor of the next page; on the last page it is absent.

```text
GET /api/audit?action=MANUAL_OVERRIDE&limit=50
200 OK
X-Audit-Next-Before: 4812
X-Audit-Trail-Mode: recording
Content-Type: application/json

GET /api/audit?action=MANUAL_OVERRIDE&limit=50&before=4812
```

Pages do not overlap and leave no gap, also while new records arrive: a new record goes on top and does not move the cursor. A caller limited by tag read rights is served page by page until `limit` records it may read are found or the trail ends; it never receives a record it may not read, and the cursor points after the last record it was given.

One record:

```json
{
  "sequence": 4812,
  "timestamp": 1794384000123456789,
  "timestamp_iso": "2026-11-11T08:00:00.123456789Z",
  "user_id": "operator1",
  "user_role": "Shift_Operator",
  "action": "MANUAL_OVERRIDE",
  "resource": "Plant/Line1/Pump1/Speed_SP",
  "old_value": "40.000000",
  "new_value": "45.000000",
  "reason": "raise flow for batch 2026-118",
  "context": { "...": "..." },
  "previous_hash": "9c1f…",
  "record_hash": "e9b4…",
  "origin": "5f0c…",
  "origin_seq": 311,
  "node": "scada-a"
}
```

`sequence` is the record's place in this server's trail (1, 2, 3 …); `timestamp` is Unix nanoseconds. `category`, `resource_name`, `diff`, `version_ref`, `signature`, `origin`, `origin_seq` and `node` are left out when empty.

## GET /api/audit/verify

Checks every record of the trail, read from the database, in order: each record's hash, its link to the record before it, that no place in the trail is empty, and that the trail does not end before its tip anchor.

```json
{ "valid": true, "total_records": 5834, "verified_records": 5834, "chains": 3 }
```

On a break, `valid` is `false`, and `broken_seq`, `reason`, `expected_hash`, `actual_hash` and `error` describe the first record that does not follow:

| `reason` | Meaning |
|---|---|
| `previous_hash` | The record does not point at the record before it in its chain, or its origin sequence is not the next one: a record was inserted or reordered. |
| `record_hash` | Its content no longer gives its hash, or the context stored with it is not the one the hash covers: it was changed. |
| `missing_record` | A place in the trail is empty: a record was removed. |
| `tip_anchor` | The trail ends before the last record the server knew of, or holds another record there: its last records were cut off, or the file was replaced by an older copy. Reported until the server restarts; `LEDGER_TIP_MISMATCH` records it. |
| `unreadable` | The database could not be read (`error` names the fault). |

`chains`, `legacy_records` and `unanchored_chains` are explained in [How verification works](/docs/platform/explanation/security-and-part-11/#how-verification-works).

## Answers

| Status | Code | When |
|---|---|---|
| `200` | | The page, or the chain check. |
| `400` | | A bad `limit` ("a whole number, 0 for every record"), `before` ("a positive whole number (the X-Audit-Next-Before of the previous page)"), `from` or `to` ("an RFC 3339 time or Unix milliseconds"). |
| `401` | | No session or token. |
| `403` | `NO_AUDIT_TRAIL` | The server has no audit trail. |
| `500` | | The audit database could not be read: "the audit trail cannot be read in full: the audit database could not be read (…); run Verify in Security > Operations audit". Never a shorter list that looks complete. |

### 403 NO_AUDIT_TRAIL

```json
{
  "status": "edition_required",
  "code": "NO_AUDIT_TRAIL",
  "edition_required": "starter",
  "error": "The audit trail requires a Starter licence or higher; this server has no audit trail."
}
```

The Free edition answers it on both routes. It also refuses, with the same code and status, the actions that would leave no record where one matters: the AI co-pilot's setpoint staging and approval (`403`, "… is refused on a server without one, as it would leave no record") and the genealogy purge. The co-pilot's PLC deploy, I/O force, PLC control and rollback tools return the same refusal as their error.

### 503 AUDIT_NOT_WRITTEN

Not an answer of these routes, but of every action that records first when its record cannot be written: in Starter, Pro and Enterprise while the trail is down (`ALM-SYS-AUDIT-DOWN`), or when a commit fails. Nothing changed.

```json
{"status": "refused", "code": "AUDIT_NOT_WRITTEN", "error": "… refused, nothing changed: the audit trail could not be written: …"}
```

Treat it as "nothing changed; retry once the audit trail is back". See [When the audit trail is down](/docs/eaxscada/how-to/when-the-audit-trail-is-down/).

## The trail's state

The trail is in one of four modes:

| Mode | Meaning |
|---|---|
| `recording` | Starter, Pro or Enterprise: the trail takes records. |
| `down` | Starter, Pro or Enterprise: the trail does not open or take writes, or its folder is refused. Every action that records first answers `503 AUDIT_NOT_WRITTEN` ([When the audit trail is down](/docs/eaxscada/how-to/when-the-audit-trail-is-down/)). |
| `read_only` | Free, with a trail kept from a paid period: read and verified, nothing written. |
| `none` | Free without a trail, or a build without DuckDB. |

Three routes give it besides the header:

| Route | Who | `audit_trail` |
|---|---|---|
| `GET /api/system/health` | Lead_Engineer, Administrator | The full state (below). |
| `GET /api/licence` | Administrator | `mode`; `reason` when down; `why` when `none`. |
| `GET /api/system/info` | Every signed-in user | `mode`; `why` when `none`. Never the reason (it may name a folder). |

`why` is `free` (the edition) or `build` (a build without DuckDB).

The full state in `GET /api/system/health`:

```json
"audit_trail": {
  "mode": "recording",
  "file": "data\\audit\\audit.duckdb",
  "size_bytes": 20480,
  "records": 6,
  "last_append": "2026-11-11T11:57:53Z",
  "append_p50_ms": 6.3,
  "append_p99_ms": 6.77,
  "append_samples": 6,
  "encrypted": false,
  "warnings": ["…"]
}
```

| Field | Meaning |
|---|---|
| `mode` | `recording`, `down`, `read_only` or `none`. |
| `reason` | When `down`: why (the open error, or the system requirement refused). |
| `file` | The trail's file (absent for `none`). |
| `size_bytes` | The file and its write-ahead log, in bytes. |
| `records` | Records in the trail. |
| `last_append` | When the last record was committed in this run, RFC 3339 UTC; absent before the first. |
| `append_p50_ms`, `append_p99_ms` | The time an append takes, from the start of its transaction to its commit: median and 99th percentile over the last 1,000 appends of this run (`append_samples`). System Health marks p99 above 50 ms amber. |
| `encrypted` | The file is encrypted with the historian's key. |
| `warnings` | The system requirement warnings found when the trail opened (removable media, little free space, implausible sync times); absent when none. |

For `none` only `mode` and the zero counters are given.

## The audit trail's own records

The trail records what happens to itself, in category `SYSTEM`:

| Action | When | What it says |
|---|---|---|
| `GENESIS` | The first record of a new trail (resource `SYSTEM_INIT`). | "System initialized with 21 CFR Part 11 compliance". |
| `AUDIT_TRAIL_STARTED` | After every genesis the server writes (resource `audit.duckdb`). | "The audit trail starts here (eaxScada \<version>)."; for a trail started by a licence installed while the server runs, "A licence that includes the audit trail was installed while the server ran: the audit trail records from here on." When an earlier JSON trail (`audit_ledger.jsonl`) is in the audit folder, it adds its name and size and that it "is not part of this trail and is not read". |
| `AUDIT_TRAIL_RESUMED` | The trail opens again after it was down; or a licence that includes the audit trail is installed on a Free server that kept a trail from a paid period (once). | After it was down: "no record was written while it was down (every action that needed one was refused)". After a Free period: "… The audit trail records again: no records were kept from \<its last record> to \<now> (Free edition)." The chain continues. |
| `AUDIT_STORAGE_WARNING` | At start, one per system-requirement warning: removable media, an SD card or eMMC, less than 20 GB free, an implausibly fast or slow sync. | The warning and the fix ([requirements](/docs/platform/explanation/security-and-part-11/#25a-audit-trail-system-requirements)). |
| `LEDGER_TIP_MISMATCH` | At start, the trail ends before the tip anchor kept in the security store, or holds another record at its place. | The anchor and the tip found. The start continues; Verify reports `tip_anchor` until the next start. |
| `LEDGER_COMMIT_UNCONFIRMED` | After the trail is opened again: a record whose commit reported an error is in the database after all. One per such record. | That record's action, resource and hash, and that it was reported as not written: its action was refused. The chain stays valid. |
| `LEDGER_FILE_SET_ASIDE` | The first record after the genesis of a trail started by `eaxscada audit-set-aside` (resource: the old file's new name). | The old file's new name, size and SHA-256, who set it aside (offline, e-signed) and why. |
| `LEDGER_FILE_REPAIRED` | The next record of a trail a checkpoint cut short, repaired by `eaxscada audit-set-aside --repair` ([Repair a trail a checkpoint cut short](/docs/eaxscada/how-to/when-the-audit-trail-is-down/#repair-a-trail-a-checkpoint-cut-short)). The chain continues. | The reason, the open error, the block and its stored and computed checksums, the verification, who repaired it (offline, e-signed), the original's new name (`audit.torn-.duckdb`) and SHA-256, the repaired file's SHA-256, the write-ahead log and the journal. |
| `AUDIT_TRAIL_RESTORED` | The last record of a trail put back by `eaxscada restore`. | The backup file, who restored it, the copy's SHA-256, its record count and last hash; that the tip anchor was reset. |

The sign-in trail (Access audit) has its own `AUDIT_TRAIL_RESTORED` entry for its own restore, with the original records kept beside it.

## See also

- [When the audit trail is down](/docs/eaxscada/how-to/when-the-audit-trail-is-down/)
- [Keep accounts and audit trails in order](/docs/eaxscada/how-to/manage-security/#2-read-and-verify-the-audit-trails)
- [Recorded first, refused without the record](/docs/platform/explanation/security-and-part-11/#recorded-first-refused-without-the-record)
- [HTTP API (generated)](/docs/eaxscada/reference/generated/http-api/)
