# Mail merge

> Send up to 100 personalized messages in one call, each rendered and queued for its own recipient.

URL: https://docs.workwae.com/guides/mail-merge

A mail merge sends one message per recipient in one call. Use it for bulk or personalized mail; for a single message, use a [send](/guides/sending).

- Up to 100 entries per call.
- Each entry becomes its own outbox entry, addressed to its `to` alone and rendered with its own `params` (see [Templates](/guides/templates#variables)).
- Because every recipient gets their own message, [tracking](/guides/tracking) numbers are per recipient.

## Send a merge

```bash tab="cURL"
curl -X POST "https://api.workwae.com/v1/accounts/$ACCOUNT_ID/mail-merges" \
  -H "Authorization: Bearer $WORKWAE_API_KEY" \
  -H "content-type: application/json" \
  -d '{
  "template": "'"$TEMPLATE_ID"'",
  "listId": "weekly-news",
  "entries": [
    { "to": { "name": "Ada", "address": "ada@example.com" }, "params": { "firstName": "Ada" } },
    { "to": { "name": "Alan", "address": "alan@example.com" }, "params": { "firstName": "Alan" } }
  ]
}'
```

```ts tab="TypeScript"
const { id, items } = await workwae.mailMerges.create({
  accountId,
  template: templateId,
  listId: "weekly-news",
  entries: [
    { to: { name: "Ada", address: "ada@example.com" }, params: { firstName: "Ada" } },
    { to: { name: "Alan", address: "alan@example.com" }, params: { firstName: "Alan" } },
  ],
});
```

## Request body

- The body takes a [send's fields](/guides/sending#fields) except `to`, `cc`, `bcc` and `render`.
- `entries[].to` is a single `{ name?, address }`; `entries[].params` are its template values.
- An entry may override `sendAt` or set its own RFC 5322 `messageId`.
- `listId` names a [suppression list](/guides/suppressions): suppressed addresses are skipped and each message gets its own unsubscribe link.

## Results

An entry that cannot be queued fails alone. The call returns 200 with one result per entry, in request order.

```ts tab="TypeScript"
for (const result of items) {
  if (result.success) console.log(result.to.address, "queued as", result.outboxId);
  else console.warn(result.to.address, result.reason, result.error);
}
```

A failed entry's `reason` is one of the API's reasons (`invalid_recipient`, `suppressed`, `template_render_failed`, `plan_limit_sends`, ...) with the HTTP `status` a single send would have returned. Queued entries then follow the normal [delivery events](/guides/sending#delivery).

## The merge object

The call stores the merge as an object, and its answer carries its `id` next to `items`. `id` is `null` when no entry was queued. Every entry it queued carries that id as `mailMergeId` (on [outbox entries](/guides/sending#delivery) and in `send.cancelled` events), and `reference` is the send's `reference`.

```json
{
  "id": "0198a2c4-7d51-7f0e-9b3a-5c1e8d2f4a60",
  "accountId": "6f1c2a4e-8b3d-4e5f-9a7b-1c2d3e4f5a6b",
  "reference": "weekly-news-42",
  "entryCount": 2,
  "createdAt": "2026-05-04T09:30:00.000Z",
  "counts": { "queued": 0, "sending": 0, "sent": 2, "failed": 0, "cancelled": 0 }
}
```

- `entryCount` is the entries the call queued; refused entries are not counted.
- `counts` is how many of its entries are in each outbox status now. An entry the outbox has deleted is no longer counted.
- A merge is kept as long as any of its entries is in the outbox, so it goes with the last of them.

```bash tab="cURL"
# One merge, with its counts
curl "https://api.workwae.com/v1/accounts/$ACCOUNT_ID/mail-merges/$MAIL_MERGE_ID" \
  -H "Authorization: Bearer $WORKWAE_API_KEY"

# The account's merges, newest first (limit, cursor)
curl "https://api.workwae.com/v1/accounts/$ACCOUNT_ID/mail-merges?limit=20" \
  -H "Authorization: Bearer $WORKWAE_API_KEY"
```

```ts tab="TypeScript"
const merge = await workwae.mailMerges.get({ accountId, mailMergeId: id });
const page = await workwae.mailMerges.list({ accountId, limit: 20 });
```

`get` and `list` need the `read` scope. An unknown merge answers 404 `mail_merge_not_found`.

## Cancel a merge

`POST .../mail-merges/{mailMergeId}/cancel` cancels every entry that is still `queued`, in one statement, with the rules of cancelling a [single send](/guides/sending#schedule): the sealed message is dropped and the status becomes `cancelled`. It needs the `send` scope and returns `{ "cancelled": n }`.

- Entries being sent, sent, failed or already cancelled are left alone, so a merge that is already underway cancels only what has not started. `cancelled` is `0` when nothing was left; the call still succeeds.
- Each cancelled entry emits a [`send.cancelled`](/guides/events/mail#event-send.cancelled) event with the merge's `mailMergeId`.

```bash tab="cURL"
curl -X POST "https://api.workwae.com/v1/accounts/$ACCOUNT_ID/mail-merges/$MAIL_MERGE_ID/cancel" \
  -H "Authorization: Bearer $WORKWAE_API_KEY"
```

```ts tab="TypeScript"
const { cancelled } = await workwae.mailMerges.cancel({ accountId, mailMergeId: id });
```
