# Fill a PDF in one call

> Send a PDF and values keyed by the printed labels, get back the filled PDF and a result for every field.

Use one-shot fill when you have a PDF and know what goes on it, and you do not need to keep the document in AppliFlo. Nothing is stored: the filled PDF comes back in the reply.

You need a key with the `draft` scope. See [API keys and scopes](https://dev.appliflo.com/guides/api-keys).

## Send the PDF and values

`POST /api/v1/fill` takes a multipart body with two fields:

| Field | What it is |
| --- | --- |
| `file` | The PDF, up to 20 MB. |
| `values` | A JSON object as a string. Keys are the labels printed on the form, values are what to write. |

**curl**

```bash
curl -X POST https://appliflo.com/api/v1/fill \
  -H "Authorization: Bearer $APPLIFLO_API_KEY" \
  -H "Idempotency-Key: fill-lease-7731" \
  -F "file=@lease-application.pdf" \
  -F 'values={"Full name":"Lan Nguyen","Date of birth":"1991-04-17","Email":"lan@example.com","Title":"Ms"}'
```

**Node**

```js
import { readFile, writeFile } from "node:fs/promises";

const form = new FormData();
form.append("file", new Blob([await readFile("lease-application.pdf")], { type: "application/pdf" }), "lease-application.pdf");
form.append("values", JSON.stringify({
  "Full name": "Lan Nguyen",
  "Date of birth": "1991-04-17",
  "Email": "lan@example.com",
  "Title": "Ms",
}));

const res = await fetch("https://appliflo.com/api/v1/fill", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}`, "Idempotency-Key": "fill-lease-7731" },
  body: form,
});
const { success, data, error } = await res.json();
if (!success) throw new Error(error);
await writeFile("lease-filled.pdf", Buffer.from(data.pdf_base64, "base64"));
```

**Python**

```python
import base64, json, os, requests

res = requests.post(
    "https://appliflo.com/api/v1/fill",
    headers={
        "Authorization": f"Bearer {os.environ['APPLIFLO_API_KEY']}",
        "Idempotency-Key": "fill-lease-7731",
    },
    files={"file": open("lease-application.pdf", "rb")},
    data={"values": json.dumps({
        "Full name": "Lan Nguyen",
        "Date of birth": "1991-04-17",
        "Email": "lan@example.com",
        "Title": "Ms",
    })},
)
body = res.json()
if not body["success"]:
    raise RuntimeError(body["error"])
open("lease-filled.pdf", "wb").write(base64.b64decode(body["data"]["pdf_base64"]))
```

## How values are matched

- A key matches a field by the label printed next to the box, such as `"Full name"`.
- A choice question, such as a row of tick boxes, is matched by its question label. Give one option, or a list of options for a question that allows several. Name an option by its printed text or its value.
- Dates, phone numbers and similar values are changed to the form's format. Those come back as `formatted`.
- Labels you send that match nothing are ignored. Fields you send nothing for are left empty.

If a label is ambiguous, use the [step by step flow](https://dev.appliflo.com/guides/upload-detect-fill) instead: it gives you each field's id, and you fill by id.

## Check the results

Look at every result before you use the PDF:

```js
const problems = data.results.filter((r) => r.status === "overflowed" || r.status === "skipped");
const unsure = data.warnings ?? [];
```

- `overflowed`: the value did not fit even at the smallest size and was not written. Shorten it, or use the step by step flow and [correct the field](https://dev.appliflo.com/guides/correct-fields).
- `skipped`: not written. `reason` is `empty`, `invalid-format`, `invalid-value`, `unsupported-type` or `not-needed` (a form rule says this box is not needed).
- `data.warnings`: fields AppliFlo was unsure about. They are never guessed, so they stay empty.
- `data.group_warnings`: choice questions AppliFlo was unsure about, also left empty.

Field ids in a one-shot reply, such as `field_12`, only name fields within that reply. To keep a document and get it signed, [upload it](https://dev.appliflo.com/guides/upload-detect-fill) and [send it for signature](https://dev.appliflo.com/guides/send-for-signature).

## Limits and AI pages

Each call counts against the shared 20 calls a minute per key, together with detect, fill and send. See [Rate limits](https://dev.appliflo.com/guides/rate-limits).

Reading a form without built-in fillable fields uses [AI pages](https://dev.appliflo.com/guides/plans), one per page. `data.ai_pages` shows what is left this month. When they run out, the call still works with built-in fillable fields only.
