# Send to many

> Send one Ready template to up to 500 people in one call, watch the batch, and fix the rows that fail.

Send to many makes one envelope per row from a Ready saved template, and sends them in the background at a steady pace. You need a key with the `read` and `send` scopes. Read the template first, as in [Send a saved template](https://dev.appliflo.com/guides/send-template): you need its `template_id`, its current `version`, its role keys and its `sender_fields`.

### Start the batch

Each row has `people`, one person per role key, and an optional `prefill` for that row's sender boxes.

**curl**

```bash
curl -X POST https://appliflo.com/api/v1/templates/$TEMPLATE_ID/bulk \
  -H "Authorization: Bearer $APPLIFLO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: renewals-2026-11" \
  -d '{
    "version": 3,
    "time_zone": "Australia/Sydney",
    "rows": [
      { "people": { "r1": { "name": "Lan Nguyen", "email": "lan@example.com" } }, "prefill": { "3": "Unit 4, 12 Rose St" } },
      { "people": { "r1": { "name": "Omar Haddad", "email": "omar@example.com" } }, "prefill": { "3": "Unit 9, 12 Rose St" } }
    ]
  }'
```

**Node**

```js
const res = await fetch(`https://appliflo.com/api/v1/templates/${templateId}/bulk`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "renewals-2026-11",
  },
  body: JSON.stringify({
    version: 3,
    time_zone: "Australia/Sydney",
    rows: [
      { people: { r1: { name: "Lan Nguyen", email: "lan@example.com" } }, prefill: { "3": "Unit 4, 12 Rose St" } },
      { people: { r1: { name: "Omar Haddad", email: "omar@example.com" } }, prefill: { "3": "Unit 9, 12 Rose St" } },
    ],
  }),
});
const { data: batch } = await res.json();
console.log(batch.batch_id, batch.counts);
```

**Python**

```python
import os, requests

headers = {"Authorization": f"Bearer {os.environ['APPLIFLO_API_KEY']}"}
batch = requests.post(
    f"https://appliflo.com/api/v1/templates/{template_id}/bulk",
    headers={**headers, "Idempotency-Key": "renewals-2026-11"},
    json={
        "version": 3,
        "time_zone": "Australia/Sydney",
        "rows": [
            {"people": {"r1": {"name": "Lan Nguyen", "email": "lan@example.com"}}, "prefill": {"3": "Unit 4, 12 Rose St"}},
            {"people": {"r1": {"name": "Omar Haddad", "email": "omar@example.com"}}, "prefill": {"3": "Unit 9, 12 Rose St"}},
        ],
    },
).json()["data"]
print(batch["batch_id"], batch["counts"])
```

The reply is `202` with `data.batch_id`, `data.counts` and a report for each row in `data.rows`. A row with a problem, such as a blank row, a missing or invalid email, or two roles sharing an email, is left out with `status: "excluded"` and its `issues`. The rest are queued.

`time_zone` makes date boxes such as "Date it's sent" use your own day. It defaults to UTC.

### Watch the batch

Poll `GET /api/v1/bulk-batches/{id}` every few seconds until `status` is `done` or `cancelled`.

**Node**

```js
let state;
do {
  await new Promise((r) => setTimeout(r, 5000));
  const poll = await fetch(`https://appliflo.com/api/v1/bulk-batches/${batchId}`, {
    headers: { Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}` },
  });
  state = (await poll.json()).data;
  console.log(state.status, state.counts);
} while (state.status !== "done" && state.status !== "cancelled");
```

**Python**

```python
import time

while True:
    time.sleep(5)
    state = requests.get(
        f"https://appliflo.com/api/v1/bulk-batches/{batch_id}",
        headers=headers,
    ).json()["data"]
    print(state["status"], state["counts"])
    if state["status"] in ("done", "cancelled"):
        break
```

| `status` | Meaning |
| --- | --- |
| `queued`, `sending` | Envelopes are going out. |
| `paused` | Waiting. `pause_reason` is `quota` (this month's envelopes ran out) or `suspended`. It carries on by itself. |
| `done` | Every row was sent, failed or left out. |
| `cancelled` | Stopped. Envelopes already sent are kept. |

Each row in `data.rows` has its `status`, its `envelope_id` once sent, and for a failure its `error`, `error_code` and `needs_fix`.

### Retry or fix failed rows

- `POST /api/v1/bulk-batches/{id}/retry-failed` sends every failed row again. It is safe to repeat: no envelope is sent twice. Use it when `error_code` is `transient`.
- When `needs_fix` is `true`, the email provider refused the address or it bounced, so retrying as is can't help. Change the row with `PATCH /api/v1/bulk-batches/{id}/rows/{row}`, which checks it again and sends it.

```bash
curl -X PATCH https://appliflo.com/api/v1/bulk-batches/$BATCH_ID/rows/2 \
  -H "Authorization: Bearer $APPLIFLO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"people":{"r1":{"name":"Omar Haddad","email":"omar.haddad@example.com"}}}'
```

To stop a batch, `POST /api/v1/bulk-batches/{id}/cancel`. Rows not sent yet are cancelled. Envelopes already sent stay sent; [void them](https://dev.appliflo.com/guides/track-envelopes#void-an-envelope) one by one if needed.

Retry, row fixes and cancel act on the first call. There is no confirm step on the REST API.

## AppliFlo library contracts

Some contracts in the AppliFlo library have not been reviewed by our lawyer yet. Sending one to many is at your own risk, under section 8A of the [Terms](https://appliflo.com/terms). Without your confirmation the batch is refused with `409 contract_risk_required`. Once your user has read and accepted that, send `"risk_accepted": true` with the batch. It is needed on every batch you start.

## Limits

- At most 500 rows a call (`422 too_many_rows`).
- The batch must fit the envelopes left this month (`422 quota_exceeded`).
- At most 2 batches sending at once per workspace (`409 too_many_running`).
- At most 10 batches started a minute per key (`429` with `Retry-After`).
- `version` must be the template's current version (`409 version_mismatch`). Read the template again and retry.
- If every row has a problem, the call is refused with `422 nothing_to_send` and the report for every row.

Each envelope sent counts once, like a single send.
