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#
| Endpoint | Scope |
|---|---|
GET /api/templates/{id}/export | templates:read |
POST /api/templates/check | templates:read |
POST /api/templates/import | templates:write |
PUT /api/templates/{id}/import | templates:write |
POST /api/templates/{id}/duplicate | templates:write |
GET /api/templates/{id}/versions | templates:read |
GET /api/templates/{id}/versions/{version} | templates:read |
GET /api/templates/{id}/versions/{version}/export | templates:read |
POST /api/templates/{id}/versions/{version}/restore | templates:write |
GET /api/blocks/{id}/export | templates:read |
POST /api/blocks/import | templates: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}/restore | templates:write |
POST /api/blocks/{id}/duplicate | templates: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.
formatdefaults tomjml. The only accepted values aremjmlandhtml.- The body heading must match:
## MJMLforformat: mjml,## HTMLforformat: html. Getting this wrong is the most common import failure. ## Plain textand## Plaintextare 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-Type | Body |
|---|---|
text/markdown or text/plain | The 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_textvalue; http://and relative URLs.
| Body field | |
|---|---|
markdown | Required. The template, in the file format above. |
binding | Optional. 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
}
errorswould block a save or break the email;warningsare worth a look. Every issue carries a machine-readablecodeand a one-linefix.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.
namedefaults to<name> (copy).slugis derived from the name and de-duplicated, unless you pass one. A slug you pass must be free, or the request fails with409 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
-
/versionslists the kept states, newest first. Each row has:version(counting up from 1);- the
nameandformatit had; saved_at, when that state was saved;replaced_at, when an edit replaced it;replaced_by(updateorrestore);- who made that edit:
replaced_by_user_id, orreplaced_by_api_key_idfor 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.templateholds the name, slug, subject, format, bodies, tags and schemas as they were. A version that has aged out of the latest 50 is a404. -
/versions/{version}/exportreturns that version as the same markdown file/exportgives for the current template. Use it to diff two versions, or to start a new template from an old one. -
/versions/{version}/restoreputs 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:
activeisn’t part of a version. Switching a block on or off records no version, and a restore leavesactiveas 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#
| Code | Status | Meaning |
|---|---|---|
INVALID_PAYLOAD | 400 | Body was neither raw markdown nor { "markdown": … }. |
IN_USE | 409 | Delete refused: still referenced. details carries the counts. |
NOT_FOUND | 404 | No template or block with that id or slug, or no such version. |
SLUG_TAKEN | 409 | A duplicate’s slug (or an import’s) is already in use. |
INSUFFICIENT_SCOPE | 403 | The key is missing templates:write. |
INVALID_PARAM_PATH | 400 | A 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_REFERENCE | 400 | A 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.