# Send a document for signature

> Pick recipients, give each one their fields, prefill what you know and send. Includes the rules for official agency forms.

Sending turns a draft document into an envelope and emails the first recipients a signing link. You need a key with the `send` scope, and a document with its fields detected. See [Upload, detect and fill](https://dev.appliflo.com/guides/upload-detect-fill).

## Send it

**curl**

```bash
curl -X POST https://appliflo.com/api/v1/documents/$DOCUMENT_ID/send \
  -H "Authorization: Bearer $APPLIFLO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: send-lease-7731" \
  -d '{
    "subject": "Please sign your lease application",
    "message": "Hi Lan, please check the details and sign.",
    "routing": "sequential",
    "recipients": [
      { "name": "Lan Nguyen", "email": "lan@example.com", "role": "signer" },
      { "name": "Sam Patel", "email": "sam@example.com", "role": "signer" },
      { "name": "Office", "email": "office@example.com", "role": "cc" }
    ],
    "assignments": [
      { "fieldId": "fld_tenant_signature", "recipientIndex": 0 },
      { "fieldId": "fld_agent_signature", "recipientIndex": 1 }
    ],
    "values": { "fld_property_address": "12 Rose St, Parramatta NSW 2150" }
  }'
```

**Node**

```js
const res = await fetch(`https://appliflo.com/api/v1/documents/${documentId}/send`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "send-lease-7731",
  },
  body: JSON.stringify({
    subject: "Please sign your lease application",
    message: "Hi Lan, please check the details and sign.",
    routing: "sequential",
    recipients: [
      { name: "Lan Nguyen", email: "lan@example.com", role: "signer" },
      { name: "Sam Patel", email: "sam@example.com", role: "signer" },
      { name: "Office", email: "office@example.com", role: "cc" },
    ],
    assignments: [
      { fieldId: "fld_tenant_signature", recipientIndex: 0 },
      { fieldId: "fld_agent_signature", recipientIndex: 1 },
    ],
    values: { fld_property_address: "12 Rose St, Parramatta NSW 2150" },
  }),
});
const { data } = await res.json();
console.log(data.envelopeId, data.invited);
```

**Python**

```python
import os, requests

headers = {"Authorization": f"Bearer {os.environ['APPLIFLO_API_KEY']}"}
res = requests.post(
    f"https://appliflo.com/api/v1/documents/{document_id}/send",
    headers={**headers, "Idempotency-Key": "send-lease-7731"},
    json={
        "subject": "Please sign your lease application",
        "message": "Hi Lan, please check the details and sign.",
        "routing": "sequential",
        "recipients": [
            {"name": "Lan Nguyen", "email": "lan@example.com", "role": "signer"},
            {"name": "Sam Patel", "email": "sam@example.com", "role": "signer"},
            {"name": "Office", "email": "office@example.com", "role": "cc"},
        ],
        "assignments": [
            {"fieldId": "fld_tenant_signature", "recipientIndex": 0},
            {"fieldId": "fld_agent_signature", "recipientIndex": 1},
        ],
        "values": {"fld_property_address": "12 Rose St, Parramatta NSW 2150"},
    },
)
data = res.json()["data"]
print(data["envelopeId"], data["invited"])
```

The reply is `201` with `data.envelopeId`, `data.invited` (people emailed now) and `data.prefilled`. Keep the envelope id to [track it](https://dev.appliflo.com/guides/track-envelopes).

## What each part does

| Key | What it does |
| --- | --- |
| `routing` | `parallel` emails everyone at once. `sequential` emails one recipient at a time, in list order. |
| `recipients[].role` | `signer` fills their fields and signs. `filler` fills their fields without signing. `cc` gets the finished copy and can never have fields. At least one signer is needed. |
| `recipients[].accessCode` | `email` (the default) emails each signer and filler a one-time code to enter before signing. `none` turns it off for that person. |
| `assignments` | Gives a field to a recipient, by field id and the recipient's place in `recipients` (0 is the first). |
| `values` | What you know already, by field id, or by group id for a choice question. Signature fields and fields you give to a recipient can't be prefilled. |
| `reminderCadence` | Automatic reminders. By default they are on, every 24 hours. You can only make them less frequent. |

## Official agency forms

AppliFlo knows the official government forms it hosts, and some agencies do not accept an electronic signature on them.

- **Fill and print only.** Some forms must be signed by hand: USCIS forms such as I-130, I-485, I-765, I-864, I-864A, I-134 and G-28, SSA SS-5, IRS 8879 and 4506-C, and the Commonwealth statutory declaration. Any send of these is refused with `422 esign_not_allowed`, whatever else you send. Fill the form, [download the filled PDF](https://dev.appliflo.com/guides/upload-detect-fill#download-the-filled-pdf), and have it printed and signed by hand.
- **Acknowledge first.** For a form whose agency may reject an electronic signature, the send needs `"esignRiskAcknowledged": true`, or it is refused with `422 esign_ack_required`. Only set it after your user has agreed. AppliFlo records the acknowledgement on the envelope. No form needs this today, but handle the code so your integration keeps working if one is added.

Sending a template uses `esign_risk_acknowledged` for the same thing. See [Send a saved template](https://dev.appliflo.com/guides/send-template).

## Common refusals

| Status | Code or message | Fix |
| --- | --- | --- |
| `422` | a field given to a `cc` | Give it to a signer or filler. |
| `422` | `esign_not_allowed` | Download the filled PDF instead of sending. |
| `422` | `esign_ack_required` | Ask your user, then send `esignRiskAcknowledged: true`. |
| `403` | `insufficient_scope` | The key needs the `send` scope. |
| `409` | `request already in progress` | The same `Idempotency-Key` is still running. Wait and retry. |
