Reference

Templates API

Create, list, read, replace, and delete stored email templates.

On this page

Every request needs Authorization: Bearer with an API key. Errors use the shapes and codes in Errors and retry decisions. The OpenAPI document has the full schemas.

Create email template

POST /v1/templates (createEmailTemplate)

Stores a template, up to 500 per organization and 100 MB of html, text and editorContent across all templates. Returns 409 template_limit_reached or template_storage_limit_reached when full. An optional Idempotency-Key header makes a retry with the same body return the first template, and the same key with a different body returns 409 idempotency_conflict.

Needs an API key with the send scope.

Request body

NameTypeRequiredNotes
formatstringNohandlebars or react-email. Always handlebars.
namestringYesA name you choose. At most 128 characters.
subjectstringYesThe subject line. At most 998 characters.
htmlstringNoThe HTML body. At most 5000000 characters.
textstringNoThe plain-text body. At most 5000000 characters.
editorContentstringNoThe dashboard editor's document. Leave it out unless you edit in the editor. At most 5000000 characters.
curl --request POST "https://ternwire.com/v1/templates" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "string",
    "subject": "string"
  }'

List email templates

GET /v1/templates (listEmailTemplates)

Lists template summaries one page at a time. Fetch a template by id to read its content.

Needs an API key with the send scope.

Query parameters

NameTypeRequiredNotes
cursorstringNo
limitintegerNoFrom 1 to 100. Default 25.
curl --request GET "https://ternwire.com/v1/templates" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"

Get email template

GET /v1/templates/{templateId} (getEmailTemplate)

Returns one template with its subject, html, text and editor content.

Needs an API key with the send scope.

Path parameters

NameTypeRequiredNotes
templateIdstringYes
curl --request GET "https://ternwire.com/v1/templates/{templateId}" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"

Replace email template

PUT /v1/templates/{templateId} (replaceEmailTemplate)

Replaces a template. Returns 409 template_storage_limit_reached when the larger content would take the organization past 100 MB. Send If-Match with the updatedAt you last read to replace only that version: a template saved since returns 409 template_changed. Without If-Match the template is replaced whatever its version.

Needs an API key with the send scope.

Path parameters

NameTypeRequiredNotes
templateIdstringYes

Headers

NameTypeRequiredNotes
If-MatchstringNo

Request body

NameTypeRequiredNotes
formatstringNohandlebars or react-email. Always handlebars.
namestringYesA name you choose. At most 128 characters.
subjectstringYesThe subject line. At most 998 characters.
htmlstringNoThe HTML body. At most 5000000 characters.
textstringNoThe plain-text body. At most 5000000 characters.
editorContentstringNoThe dashboard editor's document. Leave it out unless you edit in the editor. At most 5000000 characters.
curl --request PUT "https://ternwire.com/v1/templates/{templateId}" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "string",
    "subject": "string"
  }'

Delete email template

DELETE /v1/templates/{templateId} (deleteEmailTemplate)

Deletes the template. Returns 409 template_in_use while a scheduled or sending broadcast, or an active or paused automation, uses it.

Needs an API key with the send scope.

Path parameters

NameTypeRequiredNotes
templateIdstringYes
curl --request DELETE "https://ternwire.com/v1/templates/{templateId}" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"

Render unsaved template

POST /v1/templates/render (renderUnsavedTemplate)

Renders a template body, the same fields as createEmailTemplate takes, with values, the way a send would, and returns the subject, html and text. Nothing is saved or sent and no usage is counted. The template is checked as a save checks it (400 invalid_template), and missing values answer 422 template_render_failed with the missing names. Needs the send scope.

Request body

NameTypeRequiredNotes
templateobjectYesThe template to render, in the same shape createEmailTemplate takes.
valuesobjectNoTemplate variables, such as { "first_name": "Ada" }.
curl --request POST "https://ternwire.com/v1/templates/render" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "template": {
      "name": "string",
      "subject": "string"
    }
  }'

Render email template

POST /v1/templates/{templateId}/render (renderEmailTemplate)

Renders a saved template with values, the way a send with templateId would, and returns the subject, html and text. Nothing is sent and no usage is counted. Missing values answer 422 template_render_failed with the missing names. Needs the send scope.

Path parameters

NameTypeRequiredNotes
templateIdstringYes

Request body

NameTypeRequiredNotes
valuesobjectNoTemplate variables, such as { "first_name": "Ada" }.
curl --request POST "https://ternwire.com/v1/templates/{templateId}/render" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "values": {}
  }'

Generate email template

POST /v1/templates/generate (generateEmailTemplate)

Writes a template draft from an instruction of up to 4000 characters, or changes the draft you send, and returns it with the AI credits charged and remaining. The draft is not saved: create it with createEmailTemplate. Needs a live key with the templates:generate scope and a paid plan (402 paid_plan_required), uses the organization's AI credits (402 ai_credits_exhausted), and is limited to 10 generations a minute (429 rate_limited). A generation can take a minute or more, so allow a long timeout. A failed generation answers ai_refused, ai_output_truncated or ai_invalid_output with settlement, the credits it still used. Use format handlebars for a draft you can save through the API as it is; a react-email draft has only editorContent and needs its html and text before it can be saved.

Request body

NameTypeRequiredNotes
formatstringYeshandlebars or react-email. Always handlebars.
instructionstringYesWhat the template should say and look like, in plain words. At most 4000 characters.
draftobjectNoThe current template to refine. Leave it out to write a new one.
curl --request POST "https://ternwire.com/v1/templates/generate" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "format": "handlebars",
    "instruction": "string"
  }'

Get template generation credits

GET /v1/templates/generation-credits (getTemplateGenerationCredits)

Returns the AI credits of the current billing period: included, used, the hard cap and what remains. access is ready when generation can run, upgrade_required on the free plan, billing_inactive when billing needs attention, and unavailable when AI generation is off. Needs the templates:generate or send scope.

Needs an API key with the templates:generate scope.

curl --request GET "https://ternwire.com/v1/templates/generation-credits" \
  --header "Authorization: Bearer $TERNWIRE_API_KEY"