Skip to content

Templates

POST /v1/templates

Store a template once, send with template_id + variables. Rendering happens server-side and the stored email is the final content, so your log shows exactly what the recipient saw.

Create a template

Terminal window
curl -X POST https://api.sendbyte.africa/v1/templates \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"name": "receipt",
"subject": "Receipt for {{amount}}",
"html": "<p>Hi {{name}},</p>{{#if items}}<ul>{{#each items}}<li>{{this}}</li>{{/each}}</ul>{{/if}}",
"text": "Hi {{name}}, payment of {{amount}} received."
}'

Handlebars syntax: {{variable}}, {{#if}}, {{#each}}. Variables in HTML bodies are escaped by default (XSS-safe); use {{{variable}}} for trusted HTML fragments. Malformed templates are rejected at save time, not send time.

Author in MJML

Pass mjml instead of html to author in MJML, and SendByte compiles it to responsive, client-tested HTML at save time. Your Handlebars variables pass straight through the compilation.

{
"name": "welcome",
"subject": "Welcome {{name}}",
"mjml": "<mjml><mj-body><mj-section><mj-column><mj-text>Hi {{name}}, welcome.</mj-text></mj-column></mj-section></mj-body></mjml>"
}

The compiled HTML is stored and sent; the MJML source is kept so you can edit it later. Invalid MJML is rejected at save time with the compiler’s error.

Live preview without saving

POST /v1/templates/render with inline {subject, html | text | mjml, variables} compiles and renders in one call, returning {subject, html, text}. This is the exact send-time path, so a preview is faithful. It powers the dashboard’s template editor.

Send with a template

Terminal window
curl -X POST https://api.sendbyte.africa/v1/emails \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"from": "PayLink <receipts@paylink.ng>",
"to": "amaka@halo.ng",
"template_id": "{template_id}",
"variables": { "name": "Amaka", "amount": "₦45,000", "items": ["Data plan"] }
}'

subject is optional when template_id is set; an explicit subject, html, or text on the send call overrides the template’s.

Preview without sending

POST /v1/templates/{id}/preview with {"variables": {...}} returns the rendered subject, html, and text.

Other operations

GET /v1/templates · GET /v1/templates/{id} · PUT /v1/templates/{id} (bumps version) · DELETE /v1/templates/{id}