
# Start here for agents

For Claude and ChatGPT, [connect Tarvena through MCP](https://tarvena.pl/docs/assistants/connect.md).

Actions are `POST /api/v1/actions/<name>`. Recipes use short names.

Follow an [agent skill](https://tarvena.pl/docs/skills/outlets-and-parcels.md) for the order of a task; each public skill page ends with its HTTP actions and links the worked examples in this reference. Use `https://tarvena.pl` and [device sign-in](authentication.md); a person approves your session.

Send the recipe’s complete JSON bodies with `Content-Type: application/json` and the headers below. Save write requests before sending them. Inspect `state`, `status`, `kind` and warnings; HTTP success can contain a domain refusal.

For actions without a recipe, discover them with `GET /api/v1/actions?domain=location`, then read one schema with `GET /api/v1/actions/{actionPath}`. [Action catalogue](action-catalogue.md). Avoid downloading the multi-megabyte `/api/v1/openapi.json` for routine work. Unknown input fields are rejected.

## Write contract

Every `/api/v1` write requires these headers, including body PUT and actions without JSON `write`:

```http
Authorization: Bearer <access_token>
Content-Type: application/json
x-operat-write-contract: 4
```

Signed-in `GET /api/v1/actions` returns `writeContract:{"header":"x-operat-write-contract","value":"4"}`. Missing/wrong values refuse execution. Authentication endpoints do not use this header.

### Write envelopes

Where the action schema requires `write`, send:

```json
{"sessionId":"<fresh-uuid-1>","lane":"project-presentation","sequence":1}
```

Generate a fresh random UUID (v4) for each `<fresh-uuid-N>` placeholder; retain it for references and retries. One session UUID per client instance. `sequence` belongs to that session and keeps increasing across calls and scripts; never restart it while reusing the session. Serialize writes per project/lane. Keep the same envelope **and complete input** for an identical retry. Reusing a `sessionId`/`sequence` pair with a different input returns `attempt_payload_mismatch` and changes nothing. The server keeps only the latest settled sequence of each session and lane, so that refusal means the sequence you sent is the latest one: send the new or changed request with `sequence + 1`. A sequence older than the latest settled one returns `write_superseded` without executing; if you lost count, start a new session UUID at sequence 1. In the worked examples: `location/parcels/accept.write`, `characteristic-points/commands.input.write` and `water-design/commands.input.write` use this envelope. `files/folders/create`, `files/rename`, `files/move` and `files/trash` take `write` on the `project-files` lane. `files/folders/reserve`, `files/folders/reconcile`, `files/uploads/reserve` and `files/uploads/reconcile` take no `write` envelope, because their `operationId` or reservation identifies the attempt, but they are writes and need the `x-operat-write-contract` header. Only `files/capabilities` and `files/list` are reads. Follow each schema’s lane constraint.

`projects/create`, form creation/publication, profile mutation, evidence refresh, document create/config/regeneration/export and body PUT have their own identity/revision fields and take no `write`; send them with the `x-operat-write-contract` header like every write. A `requestId` never substitutes for a required envelope.

## Concepts and IDs

| Field | Meaning / format / retry |
| --- | --- |
| `projectId` | Use returned `project.id`. `GET /api/v1/projects.access.organizationId` identifies the **personal organization** for creation. |
| Acceptance `parcelId` | Caller-generated UUID identifying a project parcel. Use it for device parcel links. Keep it on retry. |
| `candidate.externalId` | Cadastral ID, e.g. `060901_5.0010.278`. Deduplicate by it; copy the full discovery candidate unchanged. |
| `egibOperationId` / `egibSubscriptionId` | Details `operation.id` UUID and caller `subscriptionId` UUID. Optional evidence: both null if skipped. Otherwise retain the pair for this candidate/project/query. Pending reads can be accepted. Use `expiresAt` (about 15 minutes); cancelled/expired/consumed reads may yield `egibEvidence:false`. Mismatched candidates are invalid. |
| Point / device / group / feature IDs | Caller-chosen stable strings. Keep separate identities; reuse point and parcel IDs in device links. |
| `requestId` | Project creation: nonempty string ≤128 characters. Export: UUID. Same operation/input → same ID; new operation → new ID. |
| `createRequestId` | Form creation: 1–180 characters, `^[A-Za-z0-9][A-Za-z0-9._-]*$`; e.g. `egib-demo-1`. No spaces, colons or slashes. Keep full input for retry. |
| `formId` | Saved `id`; single form uses `createRequestId`, batch members get generated IDs. Preview `draftId` is not a saved ID. |
| `changeId` | UUID for one document change. Same bytes and basis on retry; new UUID for a new edit. |
| Publication `operationId` | Caller UUID; retain the full original input until status settles. |
| Revisions | Owner-specific integers. Form download/publication `expectedRevision` = **configRevision**, never `updatedAt` (timestamp). Form edits use `expectedFormRevision`. Document body uses `body.revision`; config uses `configRevision`. Regeneration applies its preview’s body/config revisions and input token. |

`location/get` requires `domain`: `location_parcels`, `location_inspections`, `location_stakeholders` or `location_documents`:

```json
{"projectId":"<projectId>","domain":"location_parcels"}
```

## Errors and recovery

After timeout, disconnect, `outcome_unknown` or 5xx, reread the owner state or retry the identical saved request. A write may have committed. Keep its original identity and envelope until resolved.

`projects/writes/status` recovers the camera, drawing, metadata and specification operations listed in its schema notes, not every write. [Document recovery](documents.md).

| `validationCode` | Action |
| --- | --- |
| HTTP 400 `issues:[{path,code,message}]` | Correct the named field using its reason; only validation details are exposed. |
| `write_contract_missing` | Send the header/value named in the message or discovery `writeContract`. |
| `write_contract_outdated` | Refresh discovery/schema and send the current value. Refused write did not execute. |
| `write_superseded` | A later sequence settled; read current state before another intent. |
| `attempt_payload_mismatch` | That `write.sessionId` and `write.sequence` were already used for a different request; nothing changed. That sequence is the latest settled one of the session and lane. To retry the original request, resend it identically. For a new or changed request, use `write.sequence + 1`. |
| `DOCX_FORM_NO_DRAFTS` | Resolve unmatched recipients in the EGiB recipient plan. |
| `DOCX_FORM_BATCH_SOURCE_CHANGED` | Preview again; review new recipients and fingerprint. |
| `DOCX_FORM_BATCH_DRAFT_MISMATCH` | Submit every preview draft once, or omit `drafts` for defaults. |
| `DOCX_FORM_CREATE_IDENTITY_CONFLICT` | Recover original form/batch input; use a new identity only for a new intended form/batch. |
| `DOCX_FORM_LINKED_CONTENT_UNAVAILABLE` | Check linked Operat identity, project/access and body availability. |
| `pending_storage` | Settle pending document content/storage work, then reread. |
| `invalid_document_metadata` | Correct metadata using that action schema. |
| `precondition_failed`, `specification_body_changed`, `stale_calculation_context` | Read current owner state and review before making a new change. |

401 → sign in; 403 → report denied access (with `reason: "not-enabled"`: the action's feature, listed in the [action catalogue](action-catalogue.md), is not enabled for the organization); 404 → verify identity; 409 → reread owner revision; 413 → reduce/split payload; 415 → send JSON content type and body; 429 → honor `Retry-After` or bounded backoff. Document body/refresh refusals can use `status`/`reason` rather than `validationCode`.

`needs_location` → [create the project Drive folder](forms.md#save-into-project-files); `needs_connection` → reconnect Drive. Retry readiness. Form creation/download and cloud document authoring/export do not require Drive. [Sign out with JSON](authentication.md#end-the-session).

## Read one page or one selected schema

`GET /api/v1/resources?kind=blueprint&owner=operat.core` returns a small schema index and existing byte protocols. Read `GET /api/v1/schemas/{schemaId}` with a returned identity. Form contracts link config and values schemas; labels do not define validation.

[Project-file upload and recovery](files.md). [Project owner management](projects.md#project-owners).
