# Send a saved template

> Find a Ready saved template, put a person in each role, prefill the sender's boxes and send it in one call.

A saved template is a form your workspace has set up once in AppliFlo: its fields, its recipient roles in signing order, and the boxes the sender fills. Sending one is a single call. You need a key with the `read` and `send` scopes.

### Find the template and its roles

**curl**

```bash
curl "https://appliflo.com/api/v1/saved-templates?q=lease" \
  -H "Authorization: Bearer $APPLIFLO_API_KEY"
```

**Node**

```js
const res = await fetch("https://appliflo.com/api/v1/saved-templates?q=lease", {
  headers: { Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}` },
});
const { data } = await res.json();
const template = data.saved_templates.find((t) => t.status === "ready");
console.log(template.template_id, template.roles, template.sender_fields);
```

**Python**

```python
import os, requests

headers = {"Authorization": f"Bearer {os.environ['APPLIFLO_API_KEY']}"}
templates = requests.get(
    "https://appliflo.com/api/v1/saved-templates?q=lease",
    headers=headers,
).json()["data"]["saved_templates"]
template = next(t for t in templates if t["status"] == "ready")
```

Each item in `data.saved_templates` has what you need to send it:

| Key | What it is |
| --- | --- |
| `template_id` | The id to send. |
| `status` | Only `ready` templates can be sent. A `draft` is refused with `409 template_not_ready`. |
| `version` | The current version. A send uses it unless you pin another. |
| `roles` | One per recipient, in signing order. Each has a `key` such as `r1`, a `label` such as `Client`, and a `kind`: `signer` or `filler`. |
| `sender_fields` | The boxes you fill, each by its `index`. |
| `fixed_fields` | Boxes the template fills itself. `locked: false` ones can be changed with `fixed_overrides`. |

`GET /api/v1/templates/{id}` returns one template in the same shape.

To start from AppliFlo's own templates too, use `GET /api/v1/templates`: its `items` list your saved templates, AppliFlo's contract templates (`kind: "library"`) and the official government forms (`kind: "official"`, with `official_form` and `country`). Filter with `kind`, `q` (a name or a form code such as `956`) and `country`. A `ready` item with a `lib_` id sends the same way. One with `status: "draft"` is a form AppliFlo hasn't set up: `POST /api/v1/templates/{id}/create-document` imports it as a document with its fields read, and you send that document.

### Send it

Give one person per role in `recipients`, by role key or label, and prefill the sender's boxes by index.

**curl**

```bash
curl -X POST https://appliflo.com/api/v1/templates/$TEMPLATE_ID/send \
  -H "Authorization: Bearer $APPLIFLO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: lease-send-7731" \
  -d '{
    "recipients": [
      { "role": "r1", "name": "Lan Nguyen", "email": "lan@example.com" },
      { "role": "r2", "name": "Sam Patel", "email": "sam@example.com" }
    ],
    "prefill": { "3": "12 Rose St, Parramatta NSW 2150", "4": "2026-08-01" },
    "cc": [{ "email": "office@example.com", "name": "Office" }]
  }'
```

**Node**

```js
const send = await fetch(`https://appliflo.com/api/v1/templates/${templateId}/send`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "lease-send-7731",
  },
  body: JSON.stringify({
    recipients: [
      { role: "r1", name: "Lan Nguyen", email: "lan@example.com" },
      { role: "r2", name: "Sam Patel", email: "sam@example.com" },
    ],
    prefill: { "3": "12 Rose St, Parramatta NSW 2150", "4": "2026-08-01" },
    cc: [{ email: "office@example.com", name: "Office" }],
  }),
});
const { data: sent } = await send.json();
console.log(sent.envelope_id, sent.template_version);
```

**Python**

```python
sent = requests.post(
    f"https://appliflo.com/api/v1/templates/{template_id}/send",
    headers={**headers, "Idempotency-Key": "lease-send-7731"},
    json={
        "recipients": [
            {"role": "r1", "name": "Lan Nguyen", "email": "lan@example.com"},
            {"role": "r2", "name": "Sam Patel", "email": "sam@example.com"},
        ],
        "prefill": {"3": "12 Rose St, Parramatta NSW 2150", "4": "2026-08-01"},
        "cc": [{"email": "office@example.com", "name": "Office"}],
    },
).json()["data"]
print(sent["envelope_id"], sent["template_version"])
```

The reply is `201` with `data.envelope_id`, `data.invited` and `data.template_version`. The template's own copies, reminders and expiry apply. The template itself never changes, and the envelope keeps the version it was sent from.

## Options

| Key | What it does |
| --- | --- |
| `version` | Send an older finalised version. `GET /api/v1/templates/{id}/versions` lists them. |
| `subject`, `message` | Replace the template's email. Placeholders such as `{{Recipient first name}}` are filled for each person. |
| `fixed_overrides` | Change a template box that is not locked, by `fixed_fields[].index`. A locked box is refused with `422 locked_field`. |
| `local_day` | Your own date (`YYYY-MM-DD`) for boxes that print the date it was sent. |
| `esign_risk_acknowledged` | For a form whose agency may reject an electronic signature. See [official agency forms](https://dev.appliflo.com/guides/send-for-signature#official-agency-forms). |
| `risk_accepted` | For an AppliFlo library contract our lawyer has not reviewed. See [below](#appliflo-library-contracts). |
| `recipients[].accessCode` | `email` (default) or `none`, as for a [document send](https://dev.appliflo.com/guides/send-for-signature#what-each-part-does). |

A template with a box the sender signs can only be sent by a signed-in person, so an API key gets `422 signature_not_adopted`.

## AppliFlo library contracts

Some contracts in the AppliFlo library have not been reviewed by our lawyer yet. Sending one is at your own risk, under section 8A of the [Terms](https://appliflo.com/terms). If you have not accepted that for this version of the contract, in the app or on an earlier send, the send is refused with `409 contract_risk_required`. Once your user has read and accepted it, send again with `"risk_accepted": true`. AppliFlo records the acceptance only when the send goes ahead.

## Make a draft instead of sending

To change something before sending, make a draft document from the template with `POST /api/v1/saved-templates/{id}/create-document`. Its fields are already placed, so skip detection and [send it](https://dev.appliflo.com/guides/send-for-signature) when ready.

## Refusals

| Status | Code | Fix |
| --- | --- | --- |
| `409` | `template_not_ready` | An owner or admin finalises the template in the app. |
| `409` | `contract_risk_required` | See [AppliFlo library contracts](#appliflo-library-contracts). |
| `422` | `missing_person`, `unknown_role`, `duplicate_email` | One person per role, a real role key or label, a different email for each role. |
| `422` | `role_owned_field`, `unknown_field` | Prefill only `sender_fields` by their `index`. |
| `422` | `esign_not_allowed`, `esign_ack_required` | See [official agency forms](https://dev.appliflo.com/guides/send-for-signature#official-agency-forms). |
