Skip to main content
About this page · Updated 2026-11-30 19:12 UTC

What this page is: Create reusable email templates with personalization fields and structured content for campaigns and automations.

How far to trust this page: the build checked 26 names, paths, tools, scopes and error codes against the real product (0 do not match). Names, paths and numbers checked on 2026-10-22; behaviour prose not verified claim by claim.

Updated 2026-11-30 19:12 UTCLatest change: Communications MCP: templates, the brand kit and list cards can be writtenRecently updated pages

Email Templates

Create professional email templates with advanced personalization using merge variables.

Requests need an account API key (Authorization: ApiKey ak_live_...) and your workspace ID in X-Tenant-Id: see Authentication rules and Find your workspace ID.

Creating a Template​

Template creation sends the actual reusable template content to the Communications API. HTML templates should include both an HTML body and a plain-text fallback.

curl -X POST https://motorical.com/comm-api/api/templates \
-H "Authorization: ApiKey ak_live_YOUR_KEY" \
-H "X-Tenant-Id: your-tenant-uuid" \
-H "Content-Type: application/json" \
-d '{
"name": "Welcome Email",
"subject": "Welcome {{first_name|there}}!",
"type": "html",
"body_html": "<!doctype html><html><body><h1>Hello {{name|there}}</h1><p>Thanks for being part of our newsletter.</p><p><a href=\"{{unsubscribe_url}}\">Unsubscribe</a></p></body></html>",
"body_text": "Hello {{name|there}},\n\nThanks for being part of our newsletter.\n\nUnsubscribe: {{unsubscribe_url}}"
}'

For text-only templates, set type to text and send body_text:

curl -X POST https://motorical.com/comm-api/api/templates \
-H "Authorization: ApiKey ak_live_YOUR_KEY" \
-H "X-Tenant-Id: your-tenant-uuid" \
-H "Content-Type: application/json" \
-d '{
"name": "Plain Text Notice",
"subject": "Update for {{first_name|there}}",
"type": "text",
"body_text": "Hello {{name|there}},\n\nHere is your update.\n\nUnsubscribe: {{unsubscribe_url}}"
}'

Request Fields​

FieldRequiredDescription
nameYesInternal template name shown in the dashboard.
subjectYesEmail subject line. Merge variables are supported.
typeYesTemplate format. Use html for HTML templates or text for plain-text templates.
body_htmlFor html templatesConcrete HTML template body. Use email-safe HTML and inline styles for best client compatibility.
body_textRecommended for html, required for textPlain-text fallback or text-only body.

Validation​

Use the validation endpoint to check concrete template HTML/text before saving it. Validation is non-destructive: it does not create a template, campaign, log, or queued email.

curl -X POST https://motorical.com/comm-api/api/templates/validate \
-H "Authorization: ApiKey ak_live_YOUR_KEY" \
-H "X-Tenant-Id: your-tenant-uuid" \
-H "Content-Type: application/json" \
-d '{
"name": "Welcome Email",
"subject": "Welcome {{first_name|there}}!",
"type": "html",
"body_html": "<!doctype html><html><body><h1>Hello {{name|there}}</h1><p>Thanks for being part of our newsletter.</p><p><a href=\"{{unsubscribe_url}}\">Unsubscribe</a></p></body></html>",
"body_text": "Hello {{name|there}},\n\nThanks for being part of our newsletter.\n\nUnsubscribe: {{unsubscribe_url}}",
"sampleData": {
"name": "Ada Lovelace",
"unsubscribe_url": "https://example.com/unsubscribe"
}
}'

Response:

{
"success": true,
"data": {
"valid": true,
"warnings": [],
"errors": [],
"metrics": {
"htmlSize": 168,
"textLength": 75,
"subjectLength": 17,
"nodeCount": 8,
"linkCount": 1,
"imageCount": 0,
"mergeVariables": ["name", "unsubscribe_url"]
},
"preview": {
"subject": "Welcome Ada!",
"body_html": "<!doctype html><html><body><h1>Hello Ada Lovelace</h1><p>Thanks for being part of our newsletter.</p><p><a href=\"https://example.com/unsubscribe\">Unsubscribe</a></p></body></html>",
"body_text": "Hello Ada Lovelace,\n\nThanks for being part of our newsletter.\n\nUnsubscribe: https://example.com/unsubscribe"
}
}
}

The API validates the request shape before storing the template:

  • name, subject, and type are required.
  • type must match the body you provide: html templates need body_html; text templates need body_text.
  • Large HTML, high DOM node counts, too many links or images, script tags, javascript: URLs, event handlers, and missing unsubscribe placeholders are reported as warnings or errors.

Validation and errors​

POST /templates/validate returns errors (the template cannot be saved) and warnings (it can). A warning with "blocksScheduling": true means scheduling a campaign that uses this template will be refused: fix it before you try.

Warning typeMeaning
missing_unsubscribe_url (blocksScheduling)Neither body has {{unsubscribe_url}}.
unknown_merge_variable (blocksScheduling)A tag outside the closed set; variable names it and the message lists what is available.
merge_variable_in_url (blocksScheduling)A merge variable inside a link or image address (https://shop.eu/me?e={{email}}). It cannot be filled there: see Links. url and variables name it.
non_web_link_schemeA link such as sms: or whatsapp:: it works in most apps but is not click-tracked and some mail apps will not open it; scheme and url name it.
unsubscribe_url_missing_in_bodyOne of the two bodies has no unsubscribe link (the other one has).
merge_variable_without_fallbackvariables lists tags that some contacts cannot fill; add {{name|there}}.
missing_text_fallback, missing_consent_urlHints for html templates and consent-request campaigns.
Error typeMeaning
missing_name, missing_subject, missing_type, invalid_typeRequired fields; type is html or text.
missing_body_html, missing_body_textThe body that type needs.
invalid_field_typeA field that must be text is a number or an object.
name_too_long, subject_too_long, html_size_exceededA size limit; limit says which.
fallback_not_allowed, fallback_too_longA fallback on a system link, or over 100 characters.

The preview is rendered by the same code the sender uses, so Hi {{first_name|there}} previews exactly as it will be sent. Pass sampleData (name, email, ...) to choose the values.

Saving follows the same rules. POST /templates and PATCH /templates/{id} check the whole result (your changes on top of what is stored) and answer 422 TEMPLATE_INVALID with the validation object when it has errors, so a partial update can never leave a broken template. The type of a template cannot change (400 TYPE_IMMUTABLE): create a new template. Every template response carries updated_at. To edit only the version you read, send it back as expected_updated_at on PATCH /templates/{id}: if the template changed since, nothing is written and you get 409 STALE_TEMPLATE with current_updated_at. Without it the update works exactly as before.

A template edited after a campaign is scheduled does not change that campaign: scheduling froze a compiled copy. Use a test send to see the current template as a recipient would.

What happens to your HTML when a campaign is compiled​

Scheduling (or the optional compile preview) stores a sanitised copy of the HTML for the campaign: <script>, <iframe>, <object>, <embed>, <applet>, <frame>, <base> and meta-refresh tags are removed, as are inline event handlers (onclick and the like) and links or sources that run code (javascript:, vbscript:, data:text/html). Your template itself is left untouched, and the validation endpoint above reports the same findings before you save.

Every campaign message must offer a way to unsubscribe. Put {{unsubscribe_url}} in the HTML or the text body: scheduling a campaign whose template has neither is refused with 400 UNSUBSCRIBE_LINK_MISSING. Motorical also adds the List-Unsubscribe and one-click headers to each message. See how a recipient unsubscribes.

  • HTML and text content are stored as reusable template bodies and later compiled for campaigns with merge variables and unsubscribe handling.
  • Use POST /comm-api/api/templates/validate before creation and GET /comm-api/api/templates/{id} after creation to inspect the stored content before using it in a campaign.

Links. Only web links (http and https) are click-tracked: the visitor goes through a Motorical address that counts the click and lands on your page unchanged. These are left exactly as you wrote them and are not tracked: mailto: and tel: links, the unsubscribe and consent links, relative paths, #anchors, and any address that contains "unsubscribe" or "opt-out" (so a page you built for that is never counted as a click). Other schemes (sms:, whatsapp:, viber:) are not tracked either; validate reports them as non_web_link_scheme.

A merge variable cannot go inside a link address. https://shop.eu/me?e={{email}} would reach your page with the raw {{email}} (the tracked address encodes it), and it would also put a person's data in a web address. validate reports it as merge_variable_in_url and scheduling is refused with 400 MERGE_VARIABLE_IN_URL, listing each link. Put the variable in the visible text instead. The only tags allowed as a whole address are {{unsubscribe_url}} and {{consent_url}}.

The text version. If the template has a body_text, it is sent exactly as you wrote it (merge variables filled, your links and your unsubscribe line as written). If it has none, one is generated from the HTML when the campaign is compiled: paragraphs stay paragraphs, list items become - item, headings are upper case, every web link keeps its address (See the sale (https://shop.eu/sale)), and the unsubscribe link is kept. A text version you write is better than a generated one, and validate warns when an HTML template has none.

For production templates, use the same safety rules you use in the dashboard: email-safe HTML, inline CSS, a text fallback, and an unsubscribe placeholder.

Merge Variables​

Placeholders are replaced for each recipient when the message is sent. The set is closed: these are all of them, and there are no conditions or loops.

VariableFilled with
{{name}}The contact's name.
{{first_name}}The first word of the name, skipping a leading Mr, Mrs, Ms, Miss, Mx, Dr or Prof (Dr. Jane Smith gives Jane).
{{email}}The contact's email address.
{{identity_name}}The contact's organisation. Few contacts have one, so give it a fallback.
{{offer_code}}A code made for this one recipient, set per campaign before it is scheduled (Personal offer codes). Visible text only: it cannot be used in a link, and it takes no fallback.
{{unsubscribe_url}}A personal unsubscribe link, added by Motorical.
{{consent_url}}A personal consent-confirmation link. It is live only in a campaign created as a consent request; in any other campaign it is turned into an empty # link. It works whether or not the workspace setting "click counts as consent" is on.

Fallbacks. Write {{name|there}} to use there when the contact has no name. Without a fallback an empty value becomes an empty string. A fallback is at most 100 characters and cannot contain braces or line breaks. The two links (unsubscribe_url, consent_url) are always filled in and cannot take a fallback.

Escaping. Values are HTML-escaped, so a name such as <b> shows as text. In the subject, a value is put on one line.

Unknown tags are refused, not sent. A tag outside the table, a malformed one ({{ name, {{first name}}) or a fallback that is too long would reach recipients as literal braces, so scheduling a campaign that uses it is refused with 400 UNKNOWN_MERGE_VARIABLE, and the list of offending tags is in variables. Saving the template is still allowed, so you can fix a draft step by step. Check ahead with the validation endpoint below: it reports the tag as a warning with "blocksScheduling": true.

Template Features​

  • HTML & Text Templates — Rich HTML designs with automatic text fallbacks
  • Merge Variables — Dynamic content from a fixed set ({{name}}, {{first_name}}, {{email}}, {{identity_name}}, {{offer_code}}) with optional fallbacks (not for {{offer_code}}); there are no custom fields
  • Automatic Unsubscribe — CAN-SPAM compliant unsubscribe links added automatically
  • Template Library — Reusable templates for consistent brand communication

Template card​

A template can explain itself the same way a list does. Optional fields on create and update: description (what it is for and when to use it, at most 1000 characters), kind (newsletter, promotion, announcement, welcome, reengagement, event, notice, test or other) and, on create, derived_from (the id of a template of this workspace it was copied from). Detail and list return them with a description_check (warnings only). Saving only the card with PATCH never re-validates or touches the body.

POST /comm-api/api/templates/{id}/duplicate makes a copy named <name> (copy) with derived_from set to the original; the original is never touched.

Preview what a recipient sees​

curl -X POST https://motorical.com/comm-api/api/templates/preview \
-H "Authorization: ApiKey ak_live_YOUR_KEY" \
-H "X-Tenant-Id: your-tenant-uuid" \
-H "Content-Type: application/json" \
-d '{ "template_id": "TEMPLATE_ID", "sample": { "name": "Ada Lovelace" } }'

Send a template_id or an unsaved draft (subject with body_html and/or body_text), and optionally a contact_id of a real contact in this workspace or a sample. The preview uses the same renderer as the sender. When the template uses a name variable you get two renders, with_name and without_name, so you can see both "Hi Ada" and "Hi there". text_source tells you whether the plain-text version is the template's own (template) or generated from the HTML (generated), and links shows which links are click-tracked and why the others are not. Unsubscribe and consent links are example addresses. Nothing is sent or saved.

The rulebook, lint and fixes​

  • GET /comm-api/api/templates/rules is the rulebook, generated from the same constants the validator uses: limits, merge variables, what is removed when a campaign is compiled, link tracking rules, the text-version rule, and the full list of finding types.
  • POST /comm-api/api/templates/lint checks a saved template (template_id) or a draft. Every finding has a type from a closed list, a severity (blocks_scheduling, altered, risk or tip), a location (field, line, selector, excerpt), a plain-language why, and where one exists a fix with before, after and auto_applicable.
  • POST /comm-api/api/templates/fix applies only the safe, deterministic fixes (an unsubscribe link, a generated text version, a fallback on a bare {{name}}, removal of scripts, event handlers and javascript: addresses) in memory and returns the new result, the changes and the re-lint. It never saves anything: to keep the result, PATCH the template with result. Anything that needs a person (alt text, link destinations, wording, http links) stays a suggestion.
  • POST /comm-api/api/templates/check-links lists every link with whether it is tracked and its problems: merge_variable_in_url, relative_link, non_web_link_scheme, http_not_https, url_shortener, link_text_domain_mismatch.

Brand kit and starters​

Set the brand details once for the workspace, then build on-brand email from a starter.

curl -X PATCH https://motorical.com/comm-api/api/settings/brand-kit \
-H "Authorization: ApiKey ak_live_YOUR_KEY" \
-H "X-Tenant-Id: your-tenant-uuid" \
-H "Content-Type: application/json" \
-d '{
"sender_name": "Hat Free",
"postal_address": "Hat Free SIA, 1 Main St, Riga LV-1010, Latvia",
"colors": { "primary": "#1a5fb4" },
"font": "system_sans"
}'

The kit holds sender_name, postal_address, logo_url (https), colors (text, background, card, primary as #rrggbb), font (system_sans, arial_sans, verdana_sans, trebuchet_sans, georgia_serif or courier_mono), button_radius (0 to 24), footer_text, reply_to, tone_notes, language and description. It is a partial update: null clears a field, colours merge one by one, and an invalid value is 400 INVALID_BRAND_KIT naming the field. GET /comm-api/api/settings/brand-kit also returns missing and ready_for_starters. The sender name and postal address are asked for and never invented.

GET /comm-api/api/templates/starters lists seven starters: newsletter, promotion, announcement, welcome, reengagement, event and notice, each with its slots. They produce table-based email with inline CSS, a hidden preview line, a greeting with a fallback, a footer with your name, postal address and unsubscribe link, and a plain-text twin that keeps every link address. Text is escaped and links must be full https addresses without merge tags.

  • POST /comm-api/api/templates/starters/{key}/render shows the finished email and its lint without saving anything.
  • POST /comm-api/api/templates/from-starter saves it as a normal template: { "starter": "notice", "name": "Opening hours", "slots": { "headline": "Closed on Monday", "body": "We are closed on Monday for stocktaking." } }. It returns the template, the lint and kit_source. An inline brand overrides the stored kit field by field.

Refusals are named and write nothing: BRAND_KIT_INCOMPLETE (missing lists what to ask for), MISSING_SLOT and UNKNOWN_SLOT (slots lists them), SLOT_TOO_LONG, INVALID_SLOT_URL, STARTER_NOT_FOUND, MISSING_NAME, INVALID_KIND.

Retrieving Templates​

# Get all templates
GET /comm-api/api/templates
X-Tenant-Id: your-tenant-uuid

# Get template by ID
GET /comm-api/api/templates/{id}
X-Tenant-Id: your-tenant-uuid

Updating a Template​

curl -X PATCH https://motorical.com/comm-api/api/templates/{id} \
-H "Authorization: ApiKey ak_live_YOUR_KEY" \
-H "X-Tenant-Id: your-tenant-uuid" \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Welcome Email",
"subject": "Welcome {{first_name|there}} to our platform!",
"type": "html",
"body_html": "<p>Updated content</p><p><a href=\"{{unsubscribe_url}}\">Unsubscribe</a></p>",
"body_text": "Updated content\n\nUnsubscribe: {{unsubscribe_url}}"
}'

Deleting Templates​

# Delete a single template
DELETE /comm-api/api/templates/{id}
X-Tenant-Id: your-tenant-uuid

A template that any campaign uses cannot be deleted. That includes finished campaigns and campaigns in the recycle bin: a campaign keeps its template until the campaign itself is permanently deleted. The answer says which campaigns are in the way:

{
"success": false,
"error": "Template is in use by 3 campaigns and cannot be deleted. ...",
"code": "TEMPLATE_IN_USE",
"used_by": [{ "id": "…", "name": "November newsletter", "status": "completed", "in_recycle_bin": false }],
"used_by_count": 3
}

used_by lists the most recent campaigns and used_by_count is the total. GET /templates/{id} returns both as well, and GET /templates returns used_by_count for every template, so you can see what is safe to delete before you try.

To delete several at once, send DELETE /comm-api/api/templates with { "ids": ["…", "…"] } (at most 100 ids). Every id gets its own result: deleted lists the ones that went, and failed lists the rest with a reason: INVALID_ID (not a valid id), NOT_FOUND (no such template in this workspace; it is never reported as deleted) or TEMPLATE_IN_USE (with the campaigns in the way). When nothing was deleted the status is 409 (in use), 404 (none found) or 400.

Best Practices​

  • Always include a plain-text version alongside HTML
  • Test merge variables with sample data before sending
  • Use responsive HTML for mobile compatibility
  • Keep subject lines under 60 characters
  • Include a clear call-to-action