---
title: "Templates & variables"
description: "Reference a saved template and pass per-recipient data."
url: https://www.unitpost.com/docs/templates
section: Docs
updated: 2026-07-23
---
# Templates & variables

## Templates & variables

> Reference a saved template and pass per-recipient data.

Rather than inlining HTML on every send, save a template once and reference it by ID. Pass a data object and any {{variable}} in the template is substituted at send time.

**cURL**

```bash
curl https://www.unitpost.com/api/v1/emails \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "you@yourdomain.com",
    "to": "customer@acme.com",
    "template": { "id": "tmpl_123" },
    "data": { "first_name": "Sam", "plan": "Pro" }
  }'
```

**Node.js**

```ts
await fetch("https://www.unitpost.com/api/v1/emails", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.UNITPOST_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    from: "you@yourdomain.com",
    to: "customer@acme.com",
    template: { id: "tmpl_123" },
    data: { first_name: "Sam", plan: "Pro" },
  }),
});
```

**Python**

```python
requests.post(
    "https://www.unitpost.com/api/v1/emails",
    headers={"Authorization": f"Bearer {os.environ['UNITPOST_API_KEY']}"},
    json={
        "from": "you@yourdomain.com",
        "to": "customer@acme.com",
        "template": {"id": "tmpl_123"},
        "data": {"first_name": "Sam", "plan": "Pro"},
    },
)
```

When you send to a known contact, that contact's custom fields merge into the variables automatically — so a template can reference {{first_name}} without you re-sending it on every request.

> **Drafts can't be sent:** A template must be published before the API will send it. Referencing a draft returns a 422 with code template_not_published. Publish it in the editor first.

Templates are authored in the visual editor or in code mode with the @unitpost/email component library — manage them under Templates (/dashboard/templates). The library — every block, its props, and copy-paste snippets — is documented under the Email section in this sidebar.

## Related

- [Subscription topics](https://www.unitpost.com/docs/topics): Let contacts opt out of one kind of mail without leaving your list.
- [Sending domains](https://www.unitpost.com/docs/domains): Add SPF, DKIM, and DMARC so mail sends from your domain.
- [Open & click tracking](https://www.unitpost.com/docs/tracking): Control engagement tracking per send, template, or category.
