# Deploy preview API

> GET /api/dev/projects/{id}/deploy-preview (what a deploy would change - screens, command targets, scripts, write policy, lint - and its preview_hash), the ack a deploy must carry when it changes command targets, scripts or the write policy, the 409 and 403 refusal codes, and the DEPLOY, DEPLOY_PREVIEW_REFUSED and DEPLOY_AUTO_PREVIEW audit records.

Product: eaxScada · Type: Reference · Editions: Starter, Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/reference/deploy-preview-api/
Verified against commit 96f262d.

How to use it from the Studio: [Review what a deploy changes](/docs/eaxscada/how-to/review-what-a-deploy-changes/).

## GET /api/dev/projects/{id}/deploy-preview

What an explicit Deploy of project `{id}` would change now, compared with the deploy operators run (the stored manifest). Read-only: the bundle is built without being stored. **Lead_Engineer** or **Administrator**. `Cache-Control: no-store`.

| HTTP | When |
|---|---|
| `200` | The preview (below). |
| `401` | No session. |
| `403` | The user may not deploy (operators and supervisors). |
| `404` | No such project. |
| `405` | A method other than GET. |
| `500` | The preview could not be computed. |

```json
{
  "project_id": "default",
  "preview_hash": "3f1c...e9",
  "base": "a07b...41",
  "base_deployed_at": 1793900624000,
  "base_deployed_by": "admin",
  "next": "f325...6c",
  "screens": [{"id": "qa_pump_station", "kind": "screen", "name": "QA Pump station", "change": "changed"}],
  "command_targets": {
    "added": [{"tag": "Plant/P101/StopCmd", "where": "QA Pump station (qa_pump_station) > btn_stop", "screen_id": "qa_pump_station", "after": "action set_0; ..."}],
    "removed": [],
    "changed": [{"tag": "Plant/P102/StartCmd", "where": "...", "before_tag": "Plant/P101/StartCmd", "after_tag": "Plant/P102/StartCmd", "before": "...", "after": "..."}]
  },
  "scripts_added": [{"screen_id": "qa_pump_station", "screen_name": "QA Pump station", "kind": "run_command", "where": "...", "excerpt": "system.tag.write('Plant/P101/Reset', 1)"}],
  "scripts_removed": [],
  "write_policy_changes": [{"target": "Plant/P101/SpeedSP", "kind": "limits", "before": "min 0 max 100 (spMin/spMax)", "after": "min 0 max 120 (spMin/spMax)"}],
  "ack_required": true,
  "counts": {"screens": 1, "command_targets_added": 2, "command_targets_removed": 0, "command_targets_changed": 2,
             "scripts_added": 1, "scripts_removed": 0, "write_policy_changes": 2},
  "lint": {"ready": true, "blocking": false, "errors": 0, "warnings": 4, "items": [...]}
}
```

| Field | Meaning |
|---|---|
| `preview_hash` | SHA-256 of the preview's content with the hash of the stored manifest and of the manifest the deploy would publish. A deploy acknowledges this value. |
| `base` | Hash of the stored (deployed) manifest; `"none"` before the first deploy, when everything is "added". `base_deployed_at` (Unix ms) and `base_deployed_by` when there is one. |
| `next` | Hash of the manifest the deploy would publish. |
| `screens` | Documents added, removed or changed. `kind`: `screen`, `popup`, `report`, `3d`, `iso`, `dashboard`, `project` (pages and navigation). `change`: `added`, `removed`, `changed`. |
| `command_targets` | Writes added, removed and changed. `tag` is `(any tag)` for a write that cannot be derived (a `run_command` script, a display startup script) and `(code that can write)` for code that can reach a write. A changed row whose object now writes another tag has `before_tag` and `after_tag` (`tag` is the new one). `before` / `after` describe the write: action, values written, confirmation, interlocks, limits, screen level. |
| `scripts_added`, `scripts_removed` | Screen scripts added or removed. |
| `write_policy_changes` | `kind`: `signature`, `confirmation`, `limits`, `interlock` (per tag; a pattern tag ends with ` (pattern)`), `screen_access` (per screen). `before` is empty for a new fact, `after` for one that is gone. |
| `ack_required` | `true` when there is any command target, script or write-policy change: an explicit deploy then needs `ack`. |
| `counts` | The number of each change. |
| `lint` | The Problems panel's summary: `ready` (false while the checks are not ready), `blocking` (the project blocks deploys on errors), `errors`, `warnings`, and up to 200 `items` (errors and warnings). |

Arrays are empty, never absent, when nothing changed.

## POST /api/dev/projects/{id}/deploy: the acknowledgement

When the preview has `ack_required`, the deploy body must carry the acknowledgement:

```json
{"ack": {"preview_hash": "3f1c...e9", "reason": "Pump P-102 start moved to the new starter"}, "signature_ticket": "..."}
```

| Member | Rule |
|---|---|
| `ack.preview_hash` | Exactly the `preview_hash` the server computes at the deploy. |
| `ack.reason` | Not empty or blank; at most 1000 characters. Recorded in the `DEPLOY` record. |
| `signature_ticket` | Unchanged: when the project requires an e-signature. See [Require an e-signature to deploy](/docs/eaxscada/how-to/require-e-signature-to-deploy/#the-api). |

An `ack` sent for a preview without changes to acknowledge is ignored. The `lint_override_reason` query parameter is unchanged.

The server computes the preview again at the deploy and checks the acknowledgement right after the review gate and before the e-signature, so a refused acknowledgement never uses a signature ticket. A deploy that passes is bound to the manifest the preview compared (`next`): a change saved before the deploy is made refuses it.

### Refusals

Nothing is deployed and nothing changes. Each refusal answers the preview the server computed now:

```json
{"status": "deploy_preview_stale", "code": "deploy_preview_stale", "error": "not deployed: the project changed after the preview was shown (...)", "preview": { ... }}
```

| HTTP | `status` / `code` | When |
|---|---|---|
| `409` | `deploy_preview_ack_required` | The preview has changes to acknowledge and the body has no `ack`, no `preview_hash`, an empty or blank `reason`, or a `reason` over 1000 characters. |
| `409` | `deploy_preview_stale` | `preview_hash` is not the preview computed now (something was saved after it was read); or the project changed during the deploy's checks or while it was deployed. Read the preview again. |
| `403` | `deploy_preview_ack_refused` | The deploy comes from the AI co-pilot's account, which may not acknowledge: a person deploys it. |
| `500` | | The preview could not be computed: not deployed. |

The other deploy refusals keep their codes. The checks run in this order: the review gate, this acknowledgement (an explicit deploy only), the deploy signature (`deploy_signature_required` / `deploy_signature_refused`), the plant e-stop, the screen errors (`lint_errors`); then `503 AUDIT_NOT_WRITTEN` when the deploy's audit record cannot be written.

**Diagram: A signed deploy, from the dialog to its records** (sequence)

The Studio asks the eaxScada server what the deploy publishes and shows that meaning. The deployer's password, sent with the hash that was shown, gives a one-time ticket bound to the signer, the project and the manifest hash; when the project was saved since, nothing is signed. The Deploy then carries the ticket: the server runs the deploy checks in order, redeems the ticket against the manifest it builds at that moment, and only when every check passes records DEPLOY, moves the plant e-stop signal if it has to, publishes the signed manifest and records DEPLOY_SIGNED and DEPLOY_DONE.

**Participants**

- **Deployer** (person or role): signed in
- **Studio** (service or process): Deploy dialog
- **eaxScada** (product): server
- **Audit trail** (data store)

**Steps, in order**

1. **Deployer → Studio** (data or telemetry): Clicks Deploy
2. **Studio → eaxScada** (data or telemetry): GET …/deploy-esign
3. **eaxScada → Studio** (reply): subject: hash and meaning. of the manifest built now
4. **Deployer → Studio** (authentication): Password. Sign and deploy
5. **Studio → eaxScada** (authentication): POST …/deploy-esign/ticket. password, purpose "deploy", hash shown
6. Nothing is signed:
   1. **eaxScada → Studio** (refusal): 409 manifest_changed. saved since: the new subject to sign
   2. **eaxScada → Studio** (refusal): No ticket: 403. wrong password, API token or AI co-pilot
7. Signed:
   1. **eaxScada → Audit trail** (data or telemetry): ESIG_OBJECT_TICKET_ISSUED. recorded first: no record, no ticket
   2. **eaxScada → Studio** (reply): One-time ticket, 60 s. bound to signer, project, manifest hash
8. **Studio → eaxScada** (configuration or deploy): POST …/deploy. signature_ticket
9. **eaxScada**: Deploy checks, in order: 1  review before deploy; 2  acknowledgement of changes; 3  e-signature: the ticket; 4  plant e-stop setting; 5  screen errors
10. Check 3 refuses:
    1. **eaxScada → Audit trail** (data or telemetry): DEPLOY_SIGNATURE_REFUSED
    2. **eaxScada → Studio** (refusal): 403 deploy_signature_refused. or deploy_signature_required: no ticket. Nothing changes
11. Every check passes:
    1. **eaxScada → Audit trail** (data or telemetry): DEPLOY. recorded first
    2. **eaxScada → Audit trail** (data or telemetry): PROJECT PLANT_ESTOP_TAG. first, when the e-stop signal moves
    3. **eaxScada**: Publishes the manifest: built again under the lock; it has the signed hash
    4. Note: Saved meanwhile: not published, signal moved back, DEPLOY_SIGNATURE_REFUSED
    5. **eaxScada → Audit trail** (data or telemetry): DEPLOY_SIGNED, DEPLOY_DONE
    6. **eaxScada → Studio** (reply): Deployed

The server builds the manifest again when you sign, when it checks the signature and when it publishes: only the manifest you signed goes live.

## Audit records

| Record | Where | Content |
|---|---|---|
| `DEPLOY` | Operations audit (written before anything is deployed) | Now ends with the preview: `deploy preview <hash> acknowledged by <user>, reason: "<reason>"; N screen(s) changed; command targets A added, R removed, C changed; scripts S added, T removed; W write-policy change(s)`, or the hash, the counts and `no command target, script or write-policy change, no acknowledgement needed`. |
| `DEPLOY_PREVIEW_REFUSED` | Access audit and operations audit | A deploy refused by the acknowledgement check (`preview_ack_required`, `preview_stale`, `preview_ack_refused`), with the preview hash and the reason it was refused. |
| `DEPLOY_FAILED` | Operations audit | Also when the project was saved after the preview was checked and before the deploy was made (`409 deploy_preview_stale`; the previous deploy stays live). |
| `DEPLOY_AUTO_PREVIEW` | Access audit and operations audit | An automatic deploy (live editing) whose preview changes command targets, scripts or the write policy: the preview hash, the counts, the manifest and the previous one, once per preview, after its checks passed and before it is published. Never a refusal. Also written, once, when its preview could not be computed. |

## Related

- [Review what a deploy changes](/docs/eaxscada/how-to/review-what-a-deploy-changes/)
- [Deploy screens to operators, and live editing](/docs/eaxscada/how-to/deploy-screens-to-operators/)
- [Recorded first, refused without the record](/docs/platform/explanation/security-and-part-11/#recorded-first-refused-without-the-record)
