Generated from Postwind commit a19b2e4 OpenAPI 0.1.0 synced

Templates HTTP API

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 scope write (its own project; the argument is ignored); a name no template of the project has; sources that parse, use only {{ }}, if, for, include of 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’s auto_footer is false, {{ unsubscribe_url }} in each body once its partials are in. Each problem is a validation_failed error naming the field, with line L, column C: (or line L, column C of partial name:) in its message.
Returns
the template, the same as POST /api/v1/projects/{project_id}/templates.

Arguments

  • object
  • html_bodystringrequired

    The 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’s auto_footer is false.

    example <p>Hi!</p><a href="{{ unsubscribe_url }}">Unsubscribe</a>

  • namestringrequired

    Unique in the project: 1 to 128 characters.

    example Welcome

  • kindstring

    message, the default, or partial: a fragment without a subject that other templates include as {% include "name" %}.

  • project_idstring · uuid | null

    The 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 | null

    The 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 | null

    The 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-time

    When this version was saved.

  • The template engine.

    • minijinja
  • html_bodystring
  • idstring · uuid

    The template’s id, the same in every version.

  • What a template is.

    message A message: subject, HTML, text.

    partial A fragment other templates include.

  • namestring
  • project_idstring · uuid
  • subjectstring | null

    null for a partial.

  • text_bodystring | null

    null: the text is made from the HTML when the message is sent.

  • versioninteger · uint32

    From 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