05 · MailMarco API
Templates
Templates are append-only. You add versions and publish exactly one of them; sends always render the published version.
The version model
- A template is a name plus a pointer,
currentVersion, to the published version. - A version is an immutable
subjectplus at least one ofhtml,textorreactSource. Version numbers start at 1 and are assigned server-side. - Editing means adding a new version and publishing it. Nothing is ever mutated in place, so a message sent yesterday can still be explained by the version that was live then.
- Writes take an API key; reads (
GET /v1/templatesandGET /v1/templates/:id) take a session token.
Create a template
/v1/templatesCreates an empty template with no versions.
Body
namestringrequired | 1–120 characters. |
curl -X POST https://api.mailmarco.com/v1/templates \
-H "authorization: Bearer $MAILMARCO_API_KEY" \
-H "content-type: application/json" \
-d '{"name":"order-receipt"}'{
"id": "7d3c9b21-4a5e-4f6a-8b7c-0d1e2f3a4b5c",
"name": "order-receipt",
"currentVersion": null
}Add a version
/v1/templates/{id}/versionsAppends a version. The version number is the current maximum plus one.
Path parameters
idstring (uuid)required | Template id. |
Body
subjectstringrequired | At least 1 character. Used as the message subject when sending. |
htmlstringoptional | HTML body. |
textstringoptional | Plain-text body. |
reactSourcestringoptional | React Email source, rendered server-side. |
curl -X POST https://api.mailmarco.com/v1/templates/$TEMPLATE_ID/versions \
-H "authorization: Bearer $MAILMARCO_API_KEY" \
-H "content-type: application/json" \
-d '{
"subject": "Receipt for {{ orderId }}",
"html": "<p>Hi {{ name }}, your total was {{ total }}.</p>",
"text": "Hi {{ name }}, your total was {{ total }}."
}'Errors
400— None ofhtml,textorreactSourcewas supplied.404— No template with that id.
Publish a version
/v1/templates/{id}/publishMarks a version published and points the template at it. Sends immediately start using it.
Path parameters
idstring (uuid)required | Template id. |
Body
versionintegerrequired | A positive version number that exists on this template. |
curl -X POST https://api.mailmarco.com/v1/templates/$TEMPLATE_ID/publish \
-H "authorization: Bearer $MAILMARCO_API_KEY" \
-H "content-type: application/json" \
-d '{"version":1}'{
"id": "7d3c9b21-4a5e-4f6a-8b7c-0d1e2f3a4b5c",
"name": "order-receipt",
"currentVersion": 1
}Errors
404— No such template, or that version number does not exist.
Sending with a template
Replace subject/html/text with a template object on the send endpoint.
{
"from": "[email protected]",
"to": "[email protected]",
"template": {
"id": "7d3c9b21-4a5e-4f6a-8b7c-0d1e2f3a4b5c",
"variables": { "name": "Ada", "orderId": "2291", "total": "€42.00" }
}
}Interpolation is deliberately not a template engine. {{ name }} resolves a bare dotted identifier such as {{ user.firstName }} and nothing else — an expression or function call renders as an empty string rather than executing. Every substituted value is HTML-escaped, and dangerous URL schemes (javascript:, vbscript:, non-image data:) are stripped so a variable dropped into an href cannot smuggle script execution. A missing variable renders as an empty string.