Templates

Store a subject and body once, with {{ variables }} for the parts that change, and send it by id. Your code sends only the values, and you can change the wording without a deploy.

Create a template

POST/v1/templates

A template has a name, a subject and an HTML body, a text body or both. You can also create and edit templates under Templates in the dashboard, with a live preview.

curl https://api.sendfern.com/v1/templates \
  -H "Authorization: Bearer $SENDFERN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Password changed",
    "subject": "{{ first_name }}, your Acme password was changed",
    "html": "<p>Hi {{ first_name }},</p><p>Your password was changed on {{ changed_on }}. Not you? <a href=\"{{ action_url }}\">Secure your account</a>.</p>",
    "text": "Hi {{ first_name }}, your password was changed on {{ changed_on }}. Not you? Secure your account: {{ action_url }}"
  }'

Body parameters

namestringrequired
Your name for the template, at most 200 characters. Recipients never see it.
subjectstringrequired
The subject line, at most 998 characters, with no line breaks. It may contain variables.
htmlstring
The HTML body. Send html, text or both.
textstring
The plain-text body.
Response · 201 Created
{
  "id": "tpl_2vR8kQm4XcN7sL1pW9eYt3",
  "name": "Password changed",
  "subject": "{{ first_name }}, your Acme password was changed",
  "html": "<p>Hi {{ first_name }},</p><p>Your password was changed on {{ changed_on }}. ...",
  "text": "Hi {{ first_name }}, your password was changed on {{ changed_on }}. ...",
  "variables": ["first_name", "changed_on", "action_url"],
  "created_at": "2026-11-28T10:19:04Z",
  "updated_at": "2026-11-28T10:19:04Z"
}

The template id starts with tpl_. variables is worked out by Sendfern; see below.

Variables

A variable is a name in double braces: {{ first_name }}. The spaces are optional, so {{first_name}} works too. Names use letters, digits and underscores. You can use variables in the subject, the HTML and the text.

Every time a template is saved, Sendfern reads its subject, HTML and text and lists the names it finds in variables, in the order they first appear. You cannot set variables yourself: a value you send is ignored. Use it to check which values a send needs.

Send with a template

Call POST /v1/emails with template_id and variables in place of subject, html and text. Everything else, such as from, to, tags, attachments and scheduled_at, works as usual. Templates also work in batch sends and with send-only keys.

curl https://api.sendfern.com/v1/emails \
  -H "Authorization: Bearer $SENDFERN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "Acme <security@acme.com>",
    "to": "user@example.com",
    "template_id": "tpl_2vR8kQm4XcN7sL1pW9eYt3",
    "variables": {
      "first_name": "Jane",
      "changed_on": "28 November 2026",
      "action_url": "https://acme.com/account/security"
    }
  }'

Rules

  • Every variable needs a value. If a name in the template's variables is missing, the send is 400 with param: "variables" and the missing names in the message. Nothing is sent. Extra names are ignored.
  • Values are strings or numbers. Anything else, such as an object, a list or a boolean, is a 400.
  • Do not send subject, html or text with a template. A request with any of them and a template_id is a 400 naming the field.
  • The template must be yours. An unknown template_id is a 400 with param: "template_id".
  • HTML values are escaped. In the HTML body, every value is HTML-escaped, so a name like <b>Jane</b> shows as text and cannot add markup. In the subject and text, values go in as given.
  • The subject stays on one line. If a value puts a line break into the rendered subject, the send is a 400 with param: "subject". The rendered subject may also be at most 998 characters.
  • Size limit. The rendered subject, HTML and text together may be at most 5 MiB of characters. Over that, the send is a 400 with param: "variables".
Response · 400 Bad Request
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_parameter",
    "message": "Missing template variables: changed_on, action_url.",
    "param": "variables"
  }
}

Sendfern fills in the template when it creates the email and stores the result on the email. The email object then has the rendered subject, and GET /v1/emails/{id} returns the rendered HTML and text. Emails do not record which template they came from; add a tag if you want to filter by it.

Preview a template

POST/v1/templates/{id}/render

Render a template with sample values without sending anything. The response has the rendered subject, html and text, with the same escaping as a send.

curl https://api.sendfern.com/v1/templates/tpl_2vR8kQm4XcN7sL1pW9eYt3/render \
  -H "Authorization: Bearer $SENDFERN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"variables": {"first_name": "Jane"}}'
Response · 200 OK
{
  "subject": "Jane, your Acme password was changed",
  "html": "<p>Hi Jane,</p><p>Your password was changed on {{ changed_on }}. Not you? <a href=\"{{ action_url }}\">Secure your account</a>.</p>",
  "text": "Hi Jane, your password was changed on {{ changed_on }}. Not you? Secure your account: {{ action_url }}"
}

Unlike a send, missing variables are not an error: they stay as written, such as {{ changed_on }} above, so you can see what is still to fill in. The size limit still applies.

List, update and delete

EndpointWhat it does
GET /v1/templatesLists templates, newest first. Paginated.
GET /v1/templates/{id}Gets one template.
PATCH /v1/templates/{id}Changes the fields you send. PUT replaces the whole template.
DELETE /v1/templates/{id}Deletes the template. Returns 204.
# List templates
curl https://api.sendfern.com/v1/templates \
  -H "Authorization: Bearer $SENDFERN_API_KEY"

# Get one
curl https://api.sendfern.com/v1/templates/tpl_2vR8kQm4XcN7sL1pW9eYt3 \
  -H "Authorization: Bearer $SENDFERN_API_KEY"

# Change some fields
curl -X PATCH https://api.sendfern.com/v1/templates/tpl_2vR8kQm4XcN7sL1pW9eYt3 \
  -H "Authorization: Bearer $SENDFERN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"subject": "{{ first_name }}, your password was changed"}'

# Delete
curl -X DELETE https://api.sendfern.com/v1/templates/tpl_2vR8kQm4XcN7sL1pW9eYt3 \
  -H "Authorization: Bearer $SENDFERN_API_KEY"

Every save works out variables again and sets updated_at. A template must keep a subject and at least one of html or text.

Test keys and permissions

Templates are shared between live and test mode: a template you create is used by both. Because live emails use the same templates, a test key cannot change them.

  • Test keys may list, get, render and send with templates. Creating, updating or deleting one is 403 permission_denied. Use a live key, or the dashboard in either mode.
  • Send-only keys may send with a template_id but cannot read or manage templates (403).

See Authentication for key modes and permissions, and the API reference for every template endpoint.