Docs
API reference Sending Template & block import/export

Template & block import/export

Templates and content blocks round-trip as markdown. One file holds the body, the plain-text alternative, and the parameter/section/slot schemas, so a template can live in your repository, move between workspaces, or be generated by a script.

This is the file-level counterpart to template-mode, which covers filling a template in at send time.

Required scopes#

EndpointScope
GET /api/templates/{id}/exporttemplates:read
POST /api/templates/checktemplates:read
POST /api/templates/importtemplates:write
PUT /api/templates/{id}/importtemplates:write
POST /api/templates/{id}/duplicatetemplates:write
GET /api/templates/{id}/versionstemplates:read
GET /api/templates/{id}/versions/{version}templates:read
GET /api/templates/{id}/versions/{version}/exporttemplates:read
POST /api/templates/{id}/versions/{version}/restoretemplates:write
GET /api/blocks/{id}/exporttemplates:read
POST /api/blocks/importtemplates:write
DELETE /api/templates/{id}templates:write
DELETE /api/blocks/{id}templates:write
GET /api/blocks/{id}/versions (and /{version}, /{version}/export)templates:read
POST /api/blocks/{id}/versions/{version}/restoretemplates:write
POST /api/blocks/{id}/duplicatetemplates:write

templates:* covers blocks as well as templates — there is no separate blocks: scope.

Template endpoints accept an id or a slug in the path, so you can address a template by the stable name you gave it rather than storing a UUID.

The file format#

Front matter for metadata, ## headings for everything else, code blocks for content:

---
kind: template
name: My Template
format: mjml
---

## MJML

​```html
<mjml>…</mjml>
​```

## Plain text

​```
The text/plain alternative.
​```

## Parameters

​```json
[ … ]
​```

## Sections

​```json
[ … ]
​```

## Slots

​```json
[ … ]
​```

Required: kind: template, name, and a body section matching the format. Everything else is optional — omit any schema heading you don’t use.

  • format defaults to mjml. The only accepted values are mjml and html.
  • The body heading must match: ## MJML for format: mjml, ## HTML for format: html. Getting this wrong is the most common import failure.
  • ## Plain text and ## Plaintext are both accepted.
  • Blocks use kind: block.

Export#

curl "https://api.radarsend.com/t/acme/api/templates/welcome-email/export" \
  -H "X-API-Key: $API_KEY" \
  -o welcome-email.md

Responds with text/markdown; charset=utf-8 — the raw file, not JSON. Blocks export the same way from /api/blocks/{id}/export.

Markdown import currently creates a new block via POST /api/blocks/import. There is no markdown replacement endpoint for an existing block; update an existing block through the regular JSON block endpoint.

Import as a new template#

curl -X POST "https://api.radarsend.com/t/acme/api/templates/import" \
  -H "X-API-Key: $API_KEY" \
  -H 'Content-Type: text/markdown' \
  --data-binary @welcome-email.md

Returns 201 with the created template.

Two body forms are accepted, and they are equivalent:

Content-TypeBody
text/markdown or text/plainThe raw markdown
application/json{ "markdown": "---\nkind: template\n…" }

Use the JSON form when your HTTP client makes raw bodies awkward; use text/markdown when you are posting a file straight off disk. Anything else returns 400 INVALID_PAYLOAD.

Check a template without saving it#

curl -X POST "https://app.example.com/t/acme/api/templates/check" \
  -H "X-API-Key: $API_KEY" \
  -H 'Content-Type: application/json' \
  -d "$(jq -n --rawfile md welcome-email.md '{markdown: $md}')"

Runs the same validation as an import, without saving anything, and reports every problem at once rather than stopping at the first. It needs only templates:read. It is built for converting an email from another platform, so it also lints for what such an email leaves behind:

  • the previous platform’s merge tags (*|FNAME|*, %UNSUBSCRIBELINK%, …);
  • MJML 3 syntax that current MJML drops;
  • a missing {{unsubscribe_url}};
  • a recipient condition wrapped around a section;
  • HTML typed into a rich_text value;
  • http:// and relative URLs.
Body field
markdownRequired. The template, in the file format above.
bindingOptional. Content to render, shaped like template_binding on /render. Without it, each field renders its sample, then its default.

Always returns 200:

{
  "valid": false,
  "errors": [
    {
      "severity": "error",
      "code": "FOREIGN_MERGE_TAG",
      "message": "MJML: tags from another platform: *|FNAME|* (Mailchimp)",
      "fix": "Map each to its RadarSend equivalent …"
    }
  ],
  "warnings": [],
  "template": { "name": "Welcome", "slug": "welcome-email", "format": "mjml", "parameters": 3, "sections": 1, "slots": 0 },
  "preview": null
}
  • errors would block a save or break the email; warnings are worth a look. Every issue carries a machine-readable code and a one-line fix.
  • preview ({ binding, body_html, body_text }) is present only when there are no errors. Merge fields in it render for a sample recipient, and system links point at example.com.

This is the endpoint behind the MCP check_template tool, which also returns a screenshot of the preview.

Replace an existing template#

curl -X PUT "https://api.radarsend.com/t/acme/api/templates/welcome-email/import" \
  -H "X-API-Key: $API_KEY" \
  -H 'Content-Type: text/markdown' \
  --data-binary @welcome-email.md

Replaces the body and the schemas from the file. This is a replace, not a merge: a parameter absent from the uploaded file is removed from the template.

Check what depends on a template before replacing it:

curl "https://api.radarsend.com/t/acme/api/templates/welcome-email/usage" \
  -H "X-API-Key: $API_KEY"

Broadcasts that already rendered from a template are unaffected — their content is frozen at send time. The risk is to drafts and sequences still pointing at it.

Every replace or edit keeps the state it replaced, so a bad one can be undone: see Version history.

Duplicate a template#

curl -X POST "https://api.radarsend.com/t/acme/api/templates/welcome-email/duplicate" \
  -H "X-API-Key: $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{ "name": "Welcome email v2" }'

Creates a new template copied from this one and returns it (201). The copy has the bodies, the subject, the tags and every schema. An export leaves the subject, the tags and expects_schema out, so an export → import copy loses them.

  • name defaults to <name> (copy).
  • slug is derived from the name and de-duplicated, unless you pass one. A slug you pass must be free, or the request fails with 409 SLUG_TAKEN.

Nothing uses the copy until a broadcast or email picks it. That makes it the safe place to try a change to a template that drafts depend on. The copy is validated like any new template, so a source saved before a rule existed may need fixing first.

Version history#

Each change to a template keeps the state it replaced: an edit in the app, a PUT, a markdown replace, or a restore. An edit that changes nothing keeps nothing. The latest 50 per template are kept, and deleting a template deletes its history.

GET  /api/templates/{id_or_slug}/versions
GET  /api/templates/{id_or_slug}/versions/{version}
GET  /api/templates/{id_or_slug}/versions/{version}/export
POST /api/templates/{id_or_slug}/versions/{version}/restore
  • /versions lists the kept states, newest first. Each row has:

    • version (counting up from 1);
    • the name and format it had;
    • saved_at, when that state was saved;
    • replaced_at, when an edit replaced it;
    • replaced_by (update or restore);
    • who made that edit: replaced_by_user_id, or replaced_by_api_key_id for an API key or MCP connection.

    Rows carry no bodies. The current state is the template itself and isn’t listed.

  • /versions/{version} returns one version in full. template holds the name, slug, subject, format, bodies, tags and schemas as they were. A version that has aged out of the latest 50 is a 404.

  • /versions/{version}/export returns that version as the same markdown file /export gives for the current template. Use it to diff two versions, or to start a new template from an old one.

  • /versions/{version}/restore puts the template back the way that version had it, and returns the template.

    • The slug stays as it is now, since broadcasts and clients address the template by it.
    • The restore is itself an edit: the current state becomes a new version first, so a restore can be undone the same way.
    • It is validated like any edit, so a body that breaks a rule added since is refused.

Block versions#

Content blocks keep the same history, at the same paths under /api/blocks:

GET  /api/blocks/{id_or_slug}/versions
GET  /api/blocks/{id_or_slug}/versions/{version}
GET  /api/blocks/{id_or_slug}/versions/{version}/export
POST /api/blocks/{id_or_slug}/versions/{version}/restore

The rows and responses have the same shape, with block in place of template in /versions/{version}. Two differences:

  • active isn’t part of a version. Switching a block on or off records no version, and a restore leaves active as it is now, along with the slug. Restoring an old version never switches a block back on.
  • A block edit or restore can reach sends already under way. A block in a rotate or by-rule slot is chosen as each email goes out, so changing it changes what scheduled and in-progress broadcasts send from then on. A block in a single-block slot is copied in when the broadcast is saved, like a template.

GET /api/blocks/{id} and PUT /api/blocks/{id} carry the block’s current version.

Duplicate a block#

POST /api/blocks/{id_or_slug}/duplicate (body optional: { "name", "slug" }) copies a block into a new one: slot keys, tags, bodies and every schema. It returns the copy (201) with the same name and slug defaults as a template duplicate.

The copy starts inactive (active: false). It shares the source’s slot keys, and a rotate slot picks from the active blocks whose slot keys match, so an active copy would start going out wherever the source rotates before anyone has looked at it. Switch it on with PUT /api/blocks/{id} { "active": true } when it’s ready. A by-rule slot names its blocks, so a copy never joins one.

active only governs rotate slots. A by-rule slot sends the block it names whether or not that block is active.

Keeping templates in version control#

The round-trip is stable, which makes a plain git-based workflow practical:

# Pull every template into a directory
for slug in welcome-email monthly-digest; do
  curl -s "$BASE/api/templates/$slug/export" -H "X-API-Key: $API_KEY" \
    -o "templates/$slug.md"
done

# Push a change back
curl -X PUT "$BASE/api/templates/welcome-email/import" \
  -H "X-API-Key: $API_KEY" \
  -H 'Content-Type: text/markdown' \
  --data-binary @templates/welcome-email.md

Exporting the same template twice produces identical bytes, and bodies are stored verbatim — nothing is reformatted or minified on import. So a scheduled export is a reliable drift check: a diff means someone edited the template in the app.

One wrinkle on the first export after an import: if your file has no slug in its front matter, one is generated from name (and de-duplicated if it collides), so the export comes back carrying a slug your source did not have. Put an explicit slug in front matter and the file round-trips unchanged.

Deleting a template or block#

DELETE /api/templates/{id_or_slug}
DELETE /api/blocks/{id_or_slug}

Both need templates:write and return 204 on success.

A delete is refused while the template or block is still in use — 409 IN_USE, with the usage counts in details:

{
  "error": {
    "code": "IN_USE",
    "message": "Template is referenced by active drafts or recent broadcasts",
    "details": { "active_drafts": 2, "recent_broadcasts": 1 }
  }
}

For a template, “in use” means active drafts or recent broadcasts; for a block, active drafts only. Pass ?force=true to skip the check and delete anyway.

Think about force before you reach for it. It removes the definition that in-flight drafts still point at, and its version history goes with it, so there is nothing to restore from unless you kept the markdown. Exporting first (above) gives you that copy.

Errors#

CodeStatusMeaning
INVALID_PAYLOAD400Body was neither raw markdown nor { "markdown": … }.
IN_USE409Delete refused: still referenced. details carries the counts.
NOT_FOUND404No template or block with that id or slug, or no such version.
SLUG_TAKEN409A duplicate’s slug (or an import’s) is already in use.
INSUFFICIENT_SCOPE403The key is missing templates:write.
INVALID_PARAM_PATH400A parameter used with a sub-field, e.g. {{ param.hero.url }}. Parameters are used whole; declare a separate url parameter for an image or link.
INVALID_ITEM_REFERENCE400A section row field with a sub-field or filter, e.g. {{item:headline | upcase}}.

These two apply to every template and block save, not only imports: each is a spelling that used to save but rendered empty or broke the email. An update is checked only in the bodies it rewrites.

Malformed markdown — a missing required heading, unparseable JSON in a schema block — is reported as a validation error naming the section at fault.

See errors.md for the full envelope.