Templates

API reference for listing templates and creating or updating a template by alias.

Using an AI agent? Just ask:“Save a password-reset template with a reset button.”Connect your agent →

List templates#

GET/api/v1/templates
Response · 200
{
  "data": [
    { "id": "e21a…", "alias": "welcome", "name": "Welcome", "subject": "Welcome to Acme", "updated_at": "2026-11-10T12:00:00.000Z" }
  ]
}

Create or update a template#

POST/api/v1/templates

Creates a template, or updates the one with the same alias. Returns 201 when created, 200 when updated.

Body

  • namestringrequired
    A name for you.
  • subjectstringrequired
    Subject line. Liquid variables allowed.
  • htmlstringrequired
    Email-safe HTML (tables, inline styles). Up to 500 KB.
  • aliasstring
    Stable id for your code, like welcome. Lowercase letters, numbers, - and _.
  • preheaderstring
    Preview text shown after the subject in inboxes.
Request
curl https://agent.maillayer.com/api/v1/templates \
  -H "Authorization: Bearer $MAILLAYER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Password reset",
    "alias": "password-reset",
    "subject": "Reset your password",
    "html": "<p>Hi {{ first_name | default: \"there\" }}, <a href=\"{{ link }}\">reset it here</a>.</p>"
  }'

Then send it with "template": "password-reset" and "variables": { "link": "…" }. See Templates and variables.