POST/api/v1/projects/{project_id}/templates
create_template
Creates a template, its version 1: a message (kind message, the default: a subject, an HTML body and an optional text body) or a partial (kind partial: a header, footer or signature without a subject, which templates include as {% include "name" %}, at most 3 deep), with MiniJinja variables (subscriber.email, subscriber.attributes.<name>, list.name, campaign.name, project.brand_name, unsubscribe_url, unsubscribe_all_url, confirm_url). confirm_url is set only in the confirmation message of a list with double opt-in: saving accepts it, but a campaign whose template uses it fails its launch preconditions.
- Call it
- before creating a campaign, to have something to send.
- Needs
- an admin key with
project_id, or a project key with scopewrite(its own project; the argument is ignored); a name no template of the project has; sources that parse, use only{{ }},if,for,includeof the project’s partials (no cycle) and the offered filters, and render with a sample context and the latest versions of those partials; and, for a message when the project’sauto_footeris false,{{ unsubscribe_url }}in each body once its partials are in. Each problem is avalidation_failederror naming the field, withline L, column C:(orline L, column C of partialname:) in its message. - Returns
- the template, the same as
POST /api/v1/projects/{project_id}/templates.
Arguments
- object
-
html_bodystringrequiredThe HTML body, 1 byte to 1 MiB; values are HTML-escaped. A message’s must show
{{ unsubscribe_url }}, itself or through the partials it includes, when the project’sauto_footeris false.example
<p>Hi!</p><a href="{{ unsubscribe_url }}">Unsubscribe</a> -
namestringrequiredUnique in the project: 1 to 128 characters.
example
Welcome -
kindstringmessage, the default, orpartial: a fragment without a subject that other templates include as{% include "name" %}. -
project_idstring · uuid | nullThe project to create the template in. An admin key must pass it; a project key’s own project is used and this is ignored.
-
subjectstring | nullThe subject, a template too: 1 to 998 characters, one line. A message needs one; a partial has none.
example
Welcome, {{ subscriber.attributes.first_name|default('friend') }} -
text_bodystring | nullThe text body, 1 byte to 1 MiB; null or left out: made from the HTML when the message is sent.
No other arguments are accepted.
Result
The result comes back as structuredContent, with the same JSON as a text block.
- object · all fields required
-
created_atstring · date-timeWhen this version was saved.
-
engineEngineOutputThe template engine.
- minijinja
-
html_bodystring -
idstring · uuidThe template’s id, the same in every version.
-
What a template is.
messageA message: subject, HTML, text.partialA fragment other templates include. -
namestring -
project_idstring · uuid -
subjectstring | nullnullfor a partial. -
text_bodystring | nullnull: the text is made from the HTML when the message is sent. -
versioninteger · uint32From 1, one more at each save.
≥ 0
Definitions
EngineOutput
The template engine.
string · enum
- minijinja
TemplateKindOutput
What a template is.
string · enum
message A message: subject, HTML, text.
partial A fragment other templates include.
Errors
A failed call answers isError: true with a code from the same table as the HTTP API, and detail. How tools report errors
HTTP API
The same operation over HTTP: POST /api/v1/projects/{project_id}/templates