# Working together

Versions, live updates, a workflow of approvers and signers, comments and suggested edits, conditional clauses, page setup and editing together — for people and agents alike.


## Versions {#versions}

Every edit of a draft is a version, kept whole: who made it (the sender's side or an agent, by name), its note and how it was made. Give each edit a `note` (`PATCH /v2/documents/{id}/content`); it becomes the change log.

- `GET /v2/documents/{id}/revisions` — newest first.
- `GET /v2/documents/{id}/revisions/compare?from=&to=` — blocks added, removed, changed (the words that went and came), reformatted and shown under another condition; fields added, removed, changed; page setup.
- `POST /v2/documents/{id}/revisions/{n}/restore` — an earlier version becomes current as a new one; nothing in between is lost.
- `GET /v2/documents/{id}/blocks/{block}/history` — one paragraph's life: each version where it appeared, changed (which words went and came) or went away, by whom and with what note.
- `GET /v2/documents/{id}/changes?since=` — what changed since version `since` (by default, since it went out for approval), each block with who changed it.

Components show the same in the editor's History panel and in the paragraph history under the cursor; agents use `list_versions`, `compare_versions`, `restore_version`, `paragraph_history` and `changes_since`.

## Live updates {#live}

Every event is pushed as it happens. A component listens to its session (`GET /v2/client/session/stream`, the secret in the `Authorization` header), a server to its account (`GET /v2/events/stream`, optionally `?document=`). Each `change` names the event type, the document, the revision and who did it; read what changed through the ordinary routes. The components follow by themselves: an agent's edit appears in an open editor, a signature in a status card.

## Workflow: approvers and signers {#workflow}

A document's participants are a workflow of steps. In each step one or more people act at the same time: sign (`kind: "signer"`), approve (`"approver"`) or only get the result (`"cc"`). The next step starts when everyone in the previous one is done (`signing_order: "sequential"`; `"parallel"` runs everyone at once). The step is the participant's `order`. Typical workflows: legal approves → both sides sign; a manager approves → the client signs → the director signs last.

Colleagues come from the [directory](@team#directory) (`member`) and act in their workspace; people outside get a link. An approver reads the document and approves it (with a comment if they like) or returns it with what has to change. If nobody has signed yet, the document goes back to draft: the author sees the note, edits and sends it again, and the workflow starts over. After the first signature the text is fixed, so returning declines it.

### Approval in the draft {#approval}

When the workflow's first step is colleagues who approve, sending does not let the document out to the signers: it stays a draft out for approval (`in_approval: true`, `approval_base_revision`), and the approvers get the draft itself. On their turn an approver changes the text as they like (every change a version under their name), then approves it (`decision: "approve"`, a comment if they like) or sends it back (`decision: "return"` with the reason): `POST /v2/documents/{id}/approve` from their workspace, or `POST /v2/client/session/decision` from the component. The author sees the approvers' changes: what changed since it went out, and who changed it.

Once every approving step is done, the draft is marked approved (`approved_revision`). If the signers are named and it is ready, it goes on to them at once; with no signers it comes back to the author approved. That is how a text is approved before anyone decides who signs it, and how a template's draft is approved before its version is published. If the text changes after approval, the next sending goes to the approvers again. An agent cannot approve: the Sendforsign window opens the person's own turn, and the choice is theirs.

While it is a draft, anyone in the discussion comments (`POST …/comments` with `block` and an exact `quote`, or a reply in `thread`) and suggests edits (`POST …/suggestions`). The sender's side accepts a suggestion (it becomes a new version) or rejects it. `GET /v2/documents/{id}/review` returns the threads and suggestions, including what approvers wrote when they returned it. Agents comment and suggest (`add_comment`, `suggest_edit`) and lay out the workflow (`find_people`, `set_workflow`), but never approve or sign for a person.

## Conditional clauses {#conditions}

A block can show only when field values say so. In Markdown:

```
{{#if payment = installments}}
## Installments
The buyer pays in {{Months:number}} parts.
{{/if}}
```

Or on existing blocks: `{ "op": "set_condition", "blocks": ["p12"], "condition": "payment = installments" }`. Conditions read field keys: `=`, `!=`, `in [a, b]`, `>`, `<`, a key alone (filled), `!key` (empty), joined by `and` or `or`. The signed text and its PDF leave hidden blocks out, and fields that stand only in hidden blocks are not asked for. A decision field need not stand in the text: define it by key with `fields` on `PATCH /v2/documents/{id}`.

## Page setup {#page}

Paper size, orientation and margins: `{ "op": "set_page", "page": { "pageWidth": 11906, "pageHeight": 16838, "orientation": "landscape", "margins": { "left": 1701 } } }` (twips: 1440 per inch, 567 per cm), or the editor's Page menu. The Word file keeps everything else.

## Editing together {#together}

Everyone with an editing session on one draft edits it together, live, with each other's cursors and names. One of them saves for everyone, so versions, review and conditions work as usual; an edit from outside (an agent, a restored version) brings everyone to the new text.
