FlaresendDocs
Templates

Create a template

Store a template in the project, with Mustache-style variables.

POST/v1/templatesAPI key

Creates version 1 of a template stored in the project. Send it with template: "<name>" in Send an email. The syntax ({{name}}, {{{raw}}}, {{#if}}, {{#each}}) is described in Custom templates.

You can reuse the name of a built-in template. The stored template then wins over the built-in one for this project.

Body parameters

namestringrequired

1 to 100 characters: lowercase letters, digits, - and _, starting with a letter or digit. Must be unique in the project.

subjectstringrequired

1 to 998 characters. Variables are allowed, for example Welcome, {{first_name}}. Not HTML-escaped.

htmlstringrequired

The HTML body. Values inserted with {{…}} are HTML-escaped; {{{…}}} inserts them as is.

textstring

The plain text body. When you leave it out, sends get a text version made from the rendered HTML.

variablesVariable[]

The variables the template expects. A required variable must be present and not empty in data, or the send fails with 400 invalid_template_data.

Show variable properties
namestringrequired

The variable path, for example first_name or order.total.

requiredbooleandefault: false

Reject sends that don't provide it.

An example value. Stored with the template and returned as is.

Response

Status 201.

idstring

The template ID, for example tmpl_01K6B5A7C9E1G3J5L7N9Q1S3U5.

source'db'

Always db for stored templates.

projectIdstring

The project the template belongs to.

namestring

The template name.

subjectstring

The subject, unrendered.

htmlstring

The HTML, unrendered.

textstring | null

The text body, or null.

variablesVariable[]

The declared variables.

versionnumber

1 for a new template.

createdAtstring

ISO 8601 timestamp.

updatedAtstring

ISO 8601 timestamp.

Errors

StatusCodeWhen
400missing_bodyThe request has no body.
400invalid_bodyA field is missing or malformed, for example a name with capital letters. param names the field.
400invalid_templateA syntax error, such as an unclosed {{#if}}. param is subject, html or text.
409template_existsThe project already has a stored template with this name.