Templates
Manage templates from code or a deploy script. A template is sent with POST /v1/emails, linked to flow email steps or copied into a new campaign. Templates explained.
Draft and published version
Every template has two versions:
- the draft, which you edit (dashboard,
PATCH, AI assistant); - the published version, the only one
POST /v1/emailsand flows send.
Edits reach your users only once you publish: publishing updates every flow linked to the template. A template never published cannot be sent (409 template_not_published).
status | Meaning |
|---|---|
NEVER_PUBLISHED | Draft only, not sendable yet |
PUBLISHED | The draft is what gets sent |
UNPUBLISHED_CHANGES | The draft differs from the published version; changedFields lists what changed |
name and alias are not versioned: they change as soon as you save.
The template object
{
"id": "c41d7e2a-9b8f-4a6e-b3d2-5f1e0a9c8b7d",
"name": "Password reset",
"alias": "password-reset",
"subject": "Reset your password",
"preheader": "This link expires in {{ data.expires_in }}",
"fromName": "Acme",
"fromEmail": "security@acme.com",
"replyTo": null,
"contentFormat": "MARKDOWN",
"content": "Hi {{ contact.first_name | default: \"there\" }},\n\n[Choose a new password]({{ data.reset_url }})",
"text": null,
"variables": [
{ "name": "reset_url", "required": true, "example": "https://acme.com/reset?token=abc123" },
{ "name": "expires_in", "required": false, "example": "30 minutes" }
],
"status": "PUBLISHED",
"changedFields": [],
"published": {
"subject": "Reset your password",
"preheader": "This link expires in {{ data.expires_in }}",
"fromName": "Acme",
"fromEmail": "security@acme.com",
"replyTo": null,
"contentFormat": "MARKDOWN",
"content": "Hi {{ contact.first_name | default: \"there\" }},\n\n[Choose a new password]({{ data.reset_url }})",
"text": null,
"variables": [
{ "name": "reset_url", "required": true, "example": "https://acme.com/reset?token=abc123" },
{ "name": "expires_in", "required": false, "example": "30 minutes" }
]
},
"publishedAt": "2026-10-12T14:03:11Z",
"publishedBy": "Ada Lovelace",
"publicationRequest": null,
"createdVia": "DASHBOARD",
"createdAt": "2026-10-12T13:40:52Z",
"updatedAt": "2026-10-12T14:03:11Z",
"stats": { "sent": 1834, "delivered": 1829, "opened": 1402, "bounced": 5 },
"usage": { "flows": [{ "id": "4d5e6f7a-8b9c-4d0e-1f2a-3b4c5d6e7f8a", "name": "Account security" }] }
}
The top-level subject to variables fields are the draft; published is the version sent, null until the first publication. stats covers the last 30 days. usage.flows lists the flows with a step linked to the template. publicationRequest is set when an AI assistant asked a person to publish the draft.
{{ data.* }} reads the variables of the send, or the trigger event's properties in a flow; {{ contact.* }} reads the recipient's contact, if any. Variables reference.
Variables
variables declares the data.* values the template uses:
| Field | Meaning |
|---|---|
name | reset_url for {{ data.reset_url }} |
required | POST /v1/emails without it (absent, null or blank) answers 400 missing_variables; a flow run whose trigger event lacks it fails |
example | Fills previews and test emails |
Variables are versioned like the content: a change shows in changedFields as variables and goes live on publish. A data.* used in the content but not declared raises the undeclared_variable check.
List templates
GET /v1/templates
Every template of the space, newest first, with its 30-day stats.
curl https://api.kulamail.com/v1/templates \
-H "Authorization: Bearer ml_your_api_key"
Returns an array of template objects.
Create a template
POST /v1/templates
Creates a template as a draft. Publish it before sending.
password-reset. Lowercase letters, digits, - and _, 100 characters at most, unique in the space.MARKDOWN or BLOCKS (wrapped in the space theme), or HTML (sent as given).BLOCKS, the document as a JSON string, 512 KB at most.content. Variables allowed. Empty string: derived again.curl https://api.kulamail.com/v1/templates \
-H "Authorization: Bearer ml_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Password reset",
"alias": "password-reset",
"subject": "Reset your password",
"contentFormat": "MARKDOWN",
"content": "Hi {{ contact.first_name | default: \"there\" }},\n\n[Choose a new password]({{ data.reset_url }})\n\nThis link expires in {{ data.expires_in }}.",
"variables": [
{ "name": "reset_url", "required": true, "example": "https://acme.com/reset?token=abc123" },
{ "name": "expires_in", "example": "30 minutes" }
]
}'
Returns 201 with the template object, status: "NEVER_PUBLISHED".
| Status | Code | When |
|---|---|---|
| 400 | validation_error, bad_request, domain_not_verified | Missing field, invalid alias, or sender not on a verified domain |
| 400 | invalid_blocks | The BLOCKS content doesn't follow the format |
| 409 | alias_taken | The alias is already used in the space |
Get a template
GET /v1/templates/{template}
{template} is the id or the alias.
curl https://api.kulamail.com/v1/templates/password-reset \
-H "Authorization: Bearer ml_your_api_key"
Update a template
PATCH /v1/templates/{template}
Writes the draft; emails keep using the published version. Same fields as Create a template, all optional: fields left out stay as they are, a blank optional field is cleared.
alias takes effect immediately: calls with the old alias get 404.curl -X PATCH https://api.kulamail.com/v1/templates/password-reset \
-H "Authorization: Bearer ml_your_api_key" \
-H "Content-Type: application/json" \
-d '{ "subject": "Your password reset link" }'
Returns the template with status: "UNPUBLISHED_CHANGES" and changedFields: ["subject"].
Publish a template
POST /v1/templates/{template}/publish
Copies the draft over the published version, used by the next sends. Requires a full access key.
curl -X POST https://api.kulamail.com/v1/templates/password-reset/publish \
-H "Authorization: Bearer ml_your_api_key"
| Status | Code | When |
|---|---|---|
| 400 | bad_request, domain_not_verified | Empty content, or the sender is no longer on a verified domain |
| 409 | nothing_to_publish | The draft has no unpublished changes |
| 409 | content_blocked | A link of the draft is flagged as dangerous by Google. Checks |
Discard a draft
POST /v1/templates/{template}/discard
Resets the draft to the published version, dropping unpublished changes. Answers 409 template_not_published on a template never published.
Delete a template
DELETE /v1/templates/{template}
Answers 204. Later sends with this template get 404. A template linked to a flow step answers 409 template_in_use: detach or remove the step first.