Templates

Create a template

POST
/api/v1/templates

Creates a template and its first draft version. Drafts cannot send — render it, test it, then publish. Requires a write-scope key.

Authorization

bearerAuth write
headerAuthorizationBearer <token>

An API key from the dashboard under Settings → API keys, sent as Authorization: Bearer aem_….

Authorization has two independent axes.

The scope is ranked — a key satisfies any requirement at or below its own tier:

  • read — see messages, contacts and metrics. Changes nothing, and cannot send.
  • write — everything read does, plus managing templates, contacts, automations, segments and suppressions. This is what editing a template needs.
  • admin — everything write does, plus sending configuration: domains, senders, webhook registration, kill switch, daily cap, brand.

There is no approve scope. It was a rung once; it is not one now, and a key requested with it is rejected.

The approval grant (can_approve) is a separate boolean, not a rung. Delivering mail to a real inbox needs write and the grant. Keeping them on separate axes is what makes the review gate a control rather than a convention: a key that may propose is not automatically a key that may approve its own proposal.

Give your application the lowest tier that works. Most need write and the grant — the dashboard mints that combination as Send + manage; Manage only is the same rung with the grant withheld.

Scope: write

Header Parameters

Idempotency-Key?string

Makes a retry safe (1–256 chars, kept 24 hours). The same key with the same body replays the first success with Idempotency-Replay: true; the same key with a different body, or while the first request is still running, is 409 conflict. A failed request releases its key. Use a value tied to the thing you are creating, e.g. onboarding/user_42.

Length1 <= length <= 256

Request Body

application/json
  1. body
slug*string

kebab-case identity, unique in the project. This is what POST /api/v1/emails sends by.

Match^[a-z0-9][a-z0-9-]*$
Length2 <= length <= 60
name*string

Human label for the dashboard.

Length1 <= length <= 120
description?string
Lengthlength <= 500
category*string

transactional (receipts, resets — delivered even to unsubscribed contacts) or lifecycle (marketing email — not delivered to unsubscribed contacts). Both carry List-Unsubscribe headers and an unsubscribe footer; the category decides only who an existing unsubscribe blocks.

Value in"transactional""lifecycle"
subject*string

Subject line. Supports {{variable}} interpolation.

Length1 <= length <= 300
tsx_source*string

react.email TSX. May import only react and @react-email/components — the allowlist is enforced at compile time and a violation returns invalid_request.

Length20 <= length <= 100000
variables?array<>

Declared template variables, used to generate example props for rendering.

Itemsitems <= 40
Default[]

Response Body

Template created as an unpublished draft.

application/json
  1. response
id?string
slug?string
version?integer
status?"draft"
Value in"draft"
Example Request
curl -X POST 'https://sendandretain.com/api/v1/templates' \  -H 'Content-Type: application/json' \  -d '{  "slug": "welcome",  "name": "Welcome email",  "category": "transactional",  "subject": "Welcome to Acme, {{firstName}}",  "tsx_source": "import { Html, Head, Preview, Body, Text } from '\''@react-email/components'\'';\nexport default function Welcome({ firstName }) {\n  return (<Html><Head /><Preview>{`Welcome, ${firstName}`}</Preview><Body><Text>Hi {firstName}</Text></Body></Html>);\n}",  "variables": [    {      "name": "firstName",      "type": "string",      "required": true    }  ]}'
Example Response
{  "id": "tpl_9Xa2",  "slug": "welcome",  "version": 1,  "status": "draft"}