Appearance
Templates
A template is a saved subject plus a text and/or HTML body. Create them on the Templates page or through the API, then send one by name with /v1/send/template, passing only the text, or by ID in a batch with template_id.
The Free plan can keep 3 templates; Pro is unlimited.
Create a template
bash
curl https://api.marleyfetch.com/v1/templates \
-H "Authorization: Bearer $MARLEYFETCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Renewal reminder",
"subject": "{{first_name}}, your {{plan}} plan renews soon",
"html_body": "<p>Hi {{first_name}}, your {{plan}} plan renews next week.</p>",
"text_body": "Hi {{first_name}}, your {{plan}} plan renews next week."
}'name and subject are required, plus at least one of text_body and html_body. When you are at your plan's limit, the API returns 403 with "error": "Template limit reached".
Placeholders
Write {{variable}} anywhere in the subject or bodies. /v1/send/template fills them from the request's variables. When the template is sent to an audience, each placeholder is replaced with that member's payload value.
- Names are case-sensitive:
{{First_Name}}and{{first_name}}are different. - Spaces inside the braces are ignored:
{{ first_name }}works. - In a batch, a variable the member does not have becomes an empty string.
In a batch to a plain recipients list every placeholder becomes empty, and /send sends them literally, so keep placeholders out of both.
Send a template by name
Keep the layout and styling in the template and send only the text. Pass the template's name, the recipients and a value for each placeholder:
bash
curl https://api.marleyfetch.com/v1/send/template \
-H "Authorization: Bearer $MARLEYFETCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"template": "Renewal reminder",
"to": "ann@example.com",
"variables": { "first_name": "Ann", "plan": "Pro" }
}'It answers like /send and takes the same cc, bcc, from and Idempotency-Key. Add "enqueue": true to queue it like /v1/enqueue instead (Pro).
How values go in:
- HTML body: each value is escaped and its line breaks become
<br>, so plain text shows as written and can't add its own markup. _htmlvariables: a variable whose name ends in_html, like{{body_html}}, goes into the HTML as-is, for formatted content. Only pass HTML you trust there.- Text body and subject: values go in as-is. Line breaks in the subject become spaces.
- Every placeholder needs a value. A missing one returns
400 MISSING_FIELDwithdetails.missinglisting them all. Pass""to leave one empty. - Names must be unique. An unknown name returns
404with your template names indetails.templates. If two templates share a name, the API returns400instead of guessing, so rename one.
Send a template to an audience
bash
curl https://api.marleyfetch.com/v1/send/batch \
-H "Authorization: Bearer $MARLEYFETCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"template_id": 3, "audience_id": 12}'Other operations
GET /v1/templates | All your templates. |
GET /v1/templates/{id} | One template. |
PUT /v1/templates/{id} | Change any of name, subject, text_body, html_body. |
DELETE /v1/templates/{id} | Delete it. Batches already created are not affected. |