Skip to content
couryo

Developer guideSending

Saved templates

Couryo templates in HTML or MJML with {{name}} variables and {{name|fallback}} defaults, versions and preview, and how to send with template + variables.

View as Markdown

Save the email HTML once and send only the data each time. Templates live in the project, accept HTML or MJML and use variables in double braces.

Variables#

  • Write {{name}} in the subject, the HTML or the text. For nested values, use a dot: {{order.number}}.
  • Accepted names: letters, numbers and _, starting with a letter or _. An invalid name, such as {{full name}}, is refused on save.
  • In the HTML, values are escaped (< becomes &lt;), so user data never breaks the layout or injects code.
  • Values can be text, numbers or true/false. Every variable without a fallback needs a value: if one is missing, the send is refused with invalid_field and param = variables.<name>.
  • Without a text part, Couryo builds one from the HTML (links keep their address in parentheses).

Fallback: {{variable|fallback}}#

For values that can be missing without spoiling the email, such as the name in a greeting, write a fallback after |:

Texto
Hi {{name|there}}!
  • With "name": "Ana", it reads "Hi Ana!". Without name (or with an empty name), it reads "Hi there!".
  • A variable with a fallback never counts as missing: the send goes on and it does not show up in missing_variables.
  • The fallback can be empty ({{nickname|}}): without a value, the passage disappears. Spaces around it are ignored ({{ name | there }}).
  • The fallback is plain text: no variable inside it and no { or } braces. {{name|{{nickname}}}} is refused on save.
  • In the HTML, the fallback is escaped like any value.
  • Leave without a fallback what must really be there, such as the payment link, the Pix code or the boleto barcode line: a send without that data is then refused instead of going out incomplete.
  • In sequences, a variable without a value and without a fallback comes out empty and the contact still gets the email, with a warning on the enrollment. Through the API (POST /v1/emails), the send is still refused.

Create#

cURL
curl https://api.couryo.com/v1/templates \
  -H "Authorization: Bearer $COURYO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "welcome",
    "format": "html",
    "subject": "Welcome, {{name}}!",
    "html": "<h1>Hi, {{name}}</h1><p>Your order {{order.number}} is confirmed.</p>"
  }'

The response has the id (tpl_...), the version (starts at 1) and the variables found. The name is unique in the project and can be used instead of the id. Creating, changing and deleting need an admin key; reading and previewing, read.

With "format": "mjml", the MJML is compiled on save; on errors the answer is invalid_field with param = html and the MJML message.

Send with a template#

cURL
curl https://api.couryo.com/v1/emails \
  -H "Authorization: Bearer $COURYO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "Shop <hello@example.com>",
    "to": "ana@example.com",
    "template": "welcome",
    "variables": { "name": "Ana", "order": { "number": 1042 } }
  }'
  • With template, subject is optional (the template's is used); if you send one, it wins.
  • template and html/text in the same request: invalid_field with param = template.
  • The send uses the template's current version, and the email keeps which one: GET /v1/emails/{id} returns "template": { "id": "tpl_...", "version": 2 }.
  • It also works in the batch and in POST /v1/emails/check, which checks the content with the variables applied.

Versions#

Changing subject, html or text (PATCH /v1/templates/{id}) creates a new version; renaming alone does not. Emails already sent do not change. GET /v1/templates/{id}/versions lists them all, newest first.

Preview#

cURL
curl https://api.couryo.com/v1/templates/welcome/preview \
  -H "Authorization: Bearer $COURYO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "variables": { "name": "Ana" }, "version": 1 }'

Returns subject, html (MJML already compiled), text and missing_variables, the list of what a send would miss. Nothing is sent. In the dashboard, the Templates screen does the same, with the rendered email on the side.

Endpoints#

Method and path Scope What it does
GET /v1/templates read lists the project's templates
POST /v1/templates admin creates (201)
GET /v1/templates/{id} read one template (by id or name), current version
PATCH /v1/templates/{id} admin changes name, subject, html or text
DELETE /v1/templates/{id} admin deletes (204)
GET /v1/templates/{id}/versions read versions
POST /v1/templates/{id}/preview read preview with variables

Through MCP#

Through the MCP server, your AI agent uses list_templates, get_template and render_template (preview with variables, nothing is sent), with scope read, and create_template and update_template (new content creates a new version), with scope admin.