# Templates

A **template** is a saved subject plus a text and/or HTML body. Create them on the
[Templates](https://app.marleyfetch.com/templates) page or through the API, then send one by ID
in a [batch](https://docs.marleyfetch.com/guides/batches.md) with `template_id`.

The Free plan can keep **3** templates; Pro is unlimited.

## Create a template

```bash
curl https://api.marleyfetch.com/v1/templates \
  -H "Authorization: Bearer $MARLEYFETCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Renewal reminder",
    "subject": "{{first_name}}, your {{plan}} plan renews soon",
    "html_body": "<p>Hi {{first_name}}, your {{plan}} plan renews next week.</p>",
    "text_body": "Hi {{first_name}}, your {{plan}} plan renews next week."
  }'
```

`name` and `subject` are required, plus at least one of `text_body` and `html_body`. When you
are at your plan's limit, the API returns `403` with `"error": "Template limit reached"`.

## Placeholders

Write `{{variable}}` anywhere in the subject or bodies. When the template is sent to an
[audience](https://docs.marleyfetch.com/guides/audiences.md), each placeholder is replaced with that member's `payload` value.

- Names are case-sensitive: `{{First_Name}}` and `{{first_name}}` are different.
- Spaces inside the braces are ignored: `{{ first_name }}` works.
- A variable the member does not have becomes an empty string.

Placeholders are only filled from data in batches sent to an audience. In a batch to a plain
`recipients` list every placeholder becomes empty, and `/send` sends them literally — so keep
placeholders out of both.

## Send a template

```bash
curl https://api.marleyfetch.com/v1/send/batch \
  -H "Authorization: Bearer $MARLEYFETCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"template_id": 3, "audience_id": 12}'
```

## Other operations

| | |
| --- | --- |
| `GET /v1/templates` | All your templates. |
| `GET /v1/templates/{id}` | One template. |
| `PUT /v1/templates/{id}` | Change any of `name`, `subject`, `text_body`, `html_body`. |
| `DELETE /v1/templates/{id}` | Delete it. Batches already created are not affected. |
