> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moritosh.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

> Reusable, versioned content for messages

A template stores the subject and body of a message separately from the data that fills it in, so your application code sends `template_id` and a data object instead of building HTML or SMS copy on every request.

## Creating a template

```bash theme={null}
curl -X POST https://api.pulsewave.dev/v1/templates \
  -H "Authorization: Bearer pw_live_8f2k9q3m1n7r5t6y4u2i0o8p" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Invoice receipt",
    "channel": "email",
    "subject": "Receipt for invoice {{ invoice_number }}",
    "body": "<p>Hi {{ first_name }}, we received your payment of {{ amount_due }}.</p>"
  }'
```

Variables use `{{ variable }}` syntax. Any variable referenced in the template must be present in `template_data` when you send a message, or the field renders empty.

## Sending with a template

```json theme={null}
{
  "channel": "email",
  "to": "ada@example.com",
  "from": "billing@notifications.acme.com",
  "template_id": "tmpl_8f3e2a",
  "template_data": {
    "first_name": "Ada",
    "invoice_number": "INV-1042",
    "amount_due": "$84.00"
  }
}
```

`subject` and `html`/`text` from the template are merged with anything you pass directly on the message — fields on the message always win, so you can override a template's subject for a single send without creating a new template.

## Versioning

Every time you [update](/api-reference/templates/update) a template's `body`, Pulsewave increments its `version`. Messages keep a reference to the version that was current when they were sent, so editing a template never changes the content of messages that already went out — only future sends pick up the new version.

## Channel constraints

A template's `channel` is fixed at creation and must match the `channel` of any message that uses it. An `email` template can't be used to send an `sms` message.
