# Getting a contract in

`agreement_create` takes a wording from exactly one of four sources and starts the signature round. Choose the source by what you have.

| You have | Source | What you get |
|---|---|---|
| A standard contract the account uses again and again | `template` + `variables` | The account's own wording with the blanks filled |
| The facts of a deal, but no text | `contract_compose` → `draft` | A wording built from the clause library, reviewed by a human before it is frozen |
| A finished text | `wording` (Markdown) | Exactly your text, split into clauses |
| A finished file (PDF, scan, Word export) | `file_base64` + `filename`, or a multipart upload | The file as it is, signed as a whole |

## 1. From a template

`templates_list` shows the library of the account. Each template has a `key` (for example `shop.product-x`) and `variables`, the names it needs.

```json
{
  "template": "shop.product-x",
  "variables": { "product": "Concrete mixer M200", "price": "CHF 900" },
  "parties": [ { "name": "Jane Buyer", "email": "jane@example.com", "role": "Buyer" } ]
}
```

- Every variable must have a value, otherwise the call is refused with the list of missing names.
- These fill themselves: `date`, `title`, `party1_name`, `party1_role`, `party1_email`, and the same for party 2 and 3. Party 1 is the owner.
- Identity level and letterhead come from the template.

## 2. From the facts of a deal

`contract_compose` builds a wording from structured input: contract type, parties, governing law, forum, and the fields of that type (amount, scope, dates and so on). `catalog` lists every allowed value and which fields belong to which type.

No language model is involved in composing. The clauses are fixed texts from the ProperTrust clause library, chosen by contract type, legal system and forum. The same input gives the same wording.

```json
{
  "contract_type": "service",
  "title": "Website relaunch",
  "governing_law": "ch",
  "parties": [
    { "name": "Miller AG", "entity_type": "company", "country": "Switzerland", "representative": "Anna Miller" },
    { "name": "Bob Works GmbH", "entity_type": "company", "country": "Germany", "email": "bob@example.com" }
  ],
  "fields": { "amount": 12000, "currency": "CHF", "scope": "Design and build of the new website", "payment_terms": "50 % on signing, 50 % on delivery" },
  "save_draft": true
}
```

- Without `save_draft` the call only returns the Markdown; nothing is stored.
- With `save_draft` (write scope) the wording is stored as a draft. Your principal can open the returned `url`, read and edit it in the panel. This is the recommended path: **a human reads the wording before it is frozen.**
- Then call `agreement_create` with `"draft": "<id>"`. A draft can be turned into an agreement once.
- Languages of the clause library: English and German.

## 3. From your own text

Pass Markdown in `wording` and a `title`.

```markdown
## 1. Subject
The Seller sells the concrete mixer M200 to the Buyer for CHF 900.

## 2. Delivery
Within 14 days at the Buyer's site.

## 3. Governing law
Swiss law applies. Place of jurisdiction is Zurich.
```

How the text becomes clauses:

- Every line that starts with `## ` opens a new clause. The heading is the clause title; number it yourself if you want numbers.
- Text that stands before the first `## ` (parties, recitals) becomes one first clause called "Parties and recitals". If there is nothing there but the title, there is no such clause.
- A text without any `## ` is one single clause.
- If the text has no `# Title` line, the title is put on top.
- Bold, italics, lists and tables in Markdown are rendered in the PDF. HTML is stripped.

Write the parties into the text yourself: who they are, with address and role. The list in `parties` decides who is invited; it does not change the wording.

## 4. From a finished file

Pass the file as `file_base64` with a `filename`, or send it as multipart form data in the part `file` (REST). A `title` is required.

- The file is stored exactly as it is. Its SHA-256 is the hash of the bytes you sent, so everybody who holds the same file can check it.
- There are no clauses: each party confirms once that it has read the whole document, then signs.
- No verification block is printed into your file. The verification code is in the answer; print it yourself if the paper should carry it.

## What happens when you call `agreement_create`

1. The wording is rendered to a PDF (sources 1 to 3) on the account's letterhead, with a verification block at the end: QR code, link and code.
2. The PDF is hashed, encrypted and stored. The hash goes to the Bitcoin anchor queue.
3. The agreement is created in status `collecting`. The owner is the first party and has status `joined`.
4. Every other party gets a seat with status `invited` and a personal join link. Parties with an e-mail get the invitation by mail. Parties with a Telegram handle are contacted by the bot, see `telegram`.
5. The answer contains the id, `document_sha256`, `verify_code`, `verify_url`, and for every invited party `join_url` and `telegram_start_link`.

## Options

| Argument | Effect |
|---|---|
| `parties` | The other parties: `name`, and `email` and/or `telegram`, optional `role`. The owner is added by itself. May be empty for sources 2 to 4: parties can be added later. |
| `message` | A note shown in the invitation. |
| `pin` | 4 to 8 digits. With it, somebody who holds the paper and the PIN sees wording and parties on the public check page. Without it, the page shows status and hash only. |
| `require_level` | Identity level every signer needs. Default 1 (verified e-mail). During the beta, higher levels are granted by hand only, so a higher value can make an agreement unsignable. |
| `open_for_parties` | Keep the round open: parties can be added after others signed, and the agreement completes only on `agreement_close`. |
| `language` | `en` or `de`: language of the verification block when you pass `wording`. |
| `idempotency_key` | Send the same value again within 24 hours and you get the first agreement back instead of a second one. Use the order number or another id of your own. |

## After freezing

- The wording cannot be changed. `agreement_cancel` and a new `agreement_create` is the only way to correct it.
- The owner still has to sign too. The owner reads and signs in the panel (https://propertrust.com/app) or in Telegram like every other party; a key cannot do it.
- `agreement_wording` (content scope) returns the frozen clauses; `GET /v1/agreements/{id}/document` returns the PDF.
