Templates
A template is an email you keep and reuse. It has variables, and it is sent in the version you published.
Write a template
A template has a name, a subject and HTML, and can have a plain text version for mail apps that show no HTML. {{NAME}} marks a variable in any of the three. A name is letters, digits and _, and does not start with a digit.
curl -X POST "$OPENSEND_API_URL/v1/templates" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "order-confirmation", "subject": "Your order is on its way", "html": "<p>Total: {{PRICE}}</p>"}'The answer lists the variables that were found, and an alias: a short name of your own to send with in place of the id. Without one it is made from the name.
{ "object": "template", "id": "tmpl_07", "name": "order-confirmation", "alias": "order-confirmation", "status": "draft", "subject": "Your order is on its way", "html": "<p>Total: {{PRICE}}</p>", "text": null, "from": "", "replyTo": "", "defaults": {}, "design": null, "layout": "start", "variables": [ "PRICE" ], "version": 0, "publishedAt": null, "changed": false, "updatedAt": "2026-11-27T09:30:00.000Z", "createdAt": "2026-11-27T09:30:00.000Z"}Build it from blocks
A template does not have to be written as HTML. Give design in place of html, and the HTML and the plain text are made from it, with markup that mail apps accept. A design has a body of blocks, a style for the whole message and a preview, the line shown beside the subject.
import { OpenSend } from '@open-send/opensend' const opensend = new OpenSend() const template = await opensend.templates.create({ name: 'Order shipped', subject: 'Your order {{ORDER}} is on its way', design: { preview: 'Order {{ORDER}} has shipped', style: { backgroundColor: '#f4f4f5', maxWidth: '600px', fontFamily: 'Arial, sans-serif' }, body: [ { kind: 'Container', style: { backgroundColor: '#ffffff', padding: '24px' }, children: [ { kind: 'Heading', as: 'h2', text: 'Thanks, {{NAME}}' }, { kind: 'Text', text: 'Your order {{ORDER}} left our warehouse today.' }, { kind: 'Button', href: '{{TRACKING_URL}}', text: 'Follow your order', style: { backgroundColor: '#111111', color: '#ffffff', padding: '12px 20px' }, }, ], }, ], },}) console.log(template.variables, template.text)Section,Row,ColumnandContainerhold other blocks inchildren. ARowtakesColumnblocks only, and aColumnsits in aRowonly.Text,Heading,Button,Link,Markdown,CodeBlockandCodeInlineholdtext.Imgshows a picture andHrdraws a line.Htmlholds markup of your own intext, up to 60,000 characters. It goes into the email as you wrote it.styletakes CSS by property name, such asfontSizeorbackgroundColor. Only properties that work in mail are taken.- A variable can stand anywhere in
text. Inhrefandsrcit has to be the whole value, and what fills it has to be a full address: anything else is sent as#. - Every block gets an
id. You can set your own to find a block again.
html and text belong to the design from then on. Sending one of them to a template built from blocks is refused with template_designed. Send design again to change it, or design: null to turn it into a template written as HTML, which keeps the HTML it has.
To change a part of a design, send what to change in place of the whole design. templates.edit takes a list of operations and runs them in order on the design that is saved. Each one names a block by its id.
curl -X POST "$OPENSEND_API_URL/v1/templates/tmpl_02/edit" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "operations": [ { "op": "update", "id": "headline", "set": { "text": "Your week in review" }, "style": { "color": "#111111" } } ]}'insertaddsblockunderparent, or at the top level without one, atindexor at the end.updatechanges the fields insetand mergesstyleinto the style of the block.nulltakes a field or a property off.moveputs a block underparentatindex.removetakes one out with everything inside it, andduplicatecopies one right after itself with new ids.pagechanges thestyle, thepreviewor thefontsof the whole message.
One request takes up to 50 operations. The design has to hold after each one, by the rules a whole design follows. When one is refused nothing is saved, and the message names it by its place in the list, such as operations.2.id. The answer is the template, with the HTML and the plain text made again.
A design can use a font of your own. Host the file on your domain or a CDN and list it in fonts: its family, the address of the file in url, its format and a fallback, the fonts to use where yours does not load. A block or the page uses the font by naming its family in fontFamily.
urlis a fullhttpsaddress. A variable is not taken there.formatiswoff2,woff,truetypeoropentype.weightandstylesay what the file holds: a weight from 100 to 900 in hundreds, ornormalorbold, andnormaloritalic. List a family once for each file, up to 4 fonts in a design.- Many mail apps load no web fonts. They show the fallback, so pick one that sits close to your font.
To see what a design makes without saving anything, render it. A variable you give a value is filled in, and the rest stay as written. The design in this example lists a font, so the answer has its @font-face rule in the head and the fallback after the family.
curl -X POST "$OPENSEND_API_URL/v1/templates/render" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "design": { "fonts": [ { "family": "Inter", "fallback": "Helvetica, Arial, sans-serif", "url": "https://cdn.example.com/fonts/inter.woff2", "format": "woff2" } ], "body": [ { "kind": "Heading", "text": "Welcome, {{NAME}}", "style": { "fontFamily": "Inter" } }, { "kind": "Text", "text": "Your plan is {{PLAN}}." }, { "kind": "Button", "text": "Open your account", "href": "{{URL}}" } ] }, "variables": { "NAME": "Ada" }}'{ "html": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html dir=\"ltr\" lang=\"en\"><head><meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\"/><meta name=\"x-apple-disable-message-reformatting\"/><style>@font-face{font-family:Inter;font-style:normal;font-weight:400;font-display:swap;mso-font-alt:Helvetica;src:url(\"https://cdn.example.com/fonts/inter.woff2\") format('woff2')}</style></head><body><h1 style=\"font-family:Inter, Helvetica, Arial, sans-serif\">Welcome, Ada</h1><p style=\"font-size:14px;line-height:24px;margin-top:16px;margin-bottom:16px\">Your plan is {{PLAN}}.</p><a href=\"{{URL}}\" style=\"line-height:100%;text-decoration:none;display:inline-block;max-width:100%;mso-padding-alt:0px;padding:0px 0px 0px 0px\" target=\"_blank\"><span><!--[if mso]><i style=\"mso-font-width:0%;mso-text-raise:0\" hidden></i><![endif]--></span><span style=\"max-width:100%;display:inline-block;line-height:120%;mso-padding-alt:0px;mso-text-raise:0\">Open your account</span><span><!--[if mso]><i style=\"mso-font-width:0%\" hidden>​</i><![endif]--></span></a></body></html>", "text": "Welcome, Ada\n\nYour plan is {{PLAN}}.\n\nOpen your account {{URL}}"}Start from a ready-made template
You do not have to begin with an empty page. There are ready-made templates, called starters, for the mail most products send: sign-in codes, receipts, shipping notices, invitations, reminders and more. Each one is built from blocks. List them, by category or with a text in q.
curl "$OPENSEND_API_URL/v1/template-starters?category=marketing" \ -H "Authorization: Bearer $OPENSEND_API_KEY"In the list a starter has an id, what it is for, the subject it starts with and the styles it can be drawn in.
A style is a look: the same words and the same blocks, in other colours and type. To see a starter before you use it, ask for it in a style. The answer has its variables, its design, its defaults and the html and text it makes with the defaults filled in. A variable with a default is filled with it until a send gives a value of its own. One whose default is null has to come with every send. Nothing is saved.
curl "$OPENSEND_API_URL/v1/template-starters/verify-code?style=modern" \ -H "Authorization: Bearer $OPENSEND_API_KEY"minimal: The house look: a white card on pale grey, system type and a black button.modern: Ink teal on warm grey, with a header bar and tinted detail panels.bold: A vermilion poster block, a heavy headline and square black buttons.classic: Stationery: serif type on warm paper, a double rule and an oxblood button.dark: Near black, with lime actions and references set in a monospace face.soft: Cream and sage, rounded panels, friendly type and pill buttons.
To make a template from one, give its id as starter when you create the template, and a style when you do not want its default one.
import { OpenSend } from '@open-send/opensend' const opensend = new OpenSend() const starters = await opensend.templates.starters({ category: 'commerce' }) const template = await opensend.templates.create({ name: 'Shipping notice', starter: 'order-shipped', style: 'modern',}) console.log(starters.total, template.subject, template.defaults)The template gets the blocks of the starter, its subject and the defaults of its variables. From there it is a template built from blocks like any other: change it with templates.update or templates.edit, then publish it. A subject or defaults of your own take the place of the ones of the starter.
starterstands in place ofdesign,htmlandtext. Sending one of them with it is refused, and the message namesstarter.stylegoes withstarteronly, and an id or a style that does not exist is refused the same way, by name.- A starter written for a mailing list ends with an unsubscribe link whose address is
{{unsubscribe_url}}. That is the name a broadcast fills in for each contact.
Images are copied
An email links its images by address, and an image stops showing once that address moves or goes away. So a copy is kept of every image of a template or a broadcast, and the email that goes out links the copy. What you saved keeps the address you gave.
- A copy is made of a PNG, JPEG, GIF or WebP file of up to 5 MB at a public
httpsaddress: thesrcof anImgblock or an<img>tag, and the background image of a block. An SVG, a variable and an address that is not public are linked as they are. - Saving fetches nothing. A new address is noted as
pending, up to 50 for one save, and copied within about a minute. An email sent before that links the address as it is. - A copy that cannot be made is tried 3 times. After that the image is
failed, with thereasonin words, and emails link the address as it is.
To have the copy at once, add the image yourself. The answer has the address of the copy in url. The same address a second time answers with the copy that is there, and an image that failed is tried again.
curl -X POST "$OPENSEND_API_URL/v1/images" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "url": "https://cdn.example.com/logo.png"}'{ "object": "image", "id": "img_366370f5fd51b418111aa30a", "url": "https://api.opensend.sh/v1/files/img_366370f5fd51b418111aa30a.png", "source": "https://cdn.example.com/logo.png", "origin": "address", "status": "ready", "type": "image/png", "size": 70, "reason": null, "createdAt": "2026-11-27T09:30:00.000Z", "updatedAt": "2026-11-27T09:30:00.000Z"}The list shows what was copied and what was not. status narrows it.
curl "$OPENSEND_API_URL/v1/images?status=ready" \ -H "Authorization: Bearer $OPENSEND_API_KEY"Deleting an image deletes its copy, so emails that were already sent stop showing it. An image that a template or a broadcast still uses is copied again the next time that one is saved.
curl -X DELETE "$OPENSEND_API_URL/v1/images/img_366370f5fd51b418111aa30a" \ -H "Authorization: Bearer $OPENSEND_API_KEY"Give it a sender and defaults
A template can hold what its emails have in common, so a send does not have to repeat it.
from: the sender of an email built from it, when the send names none.replyTo: the address replies go to, when the send names none. Empty leaves it to the default of the workspace.defaults: a value for a variable, by name, used when a send gives none for it.text: the plain text version. A send that gives its owntextreplaces it.
curl -X PATCH "$OPENSEND_API_URL/v1/templates/tmpl_06" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "subject": "Welcome aboard", "from": "Acme <hello@mail.example.com>", "defaults": { "NAME": "there" }}'They are part of the version: a change to one is sent after you publish again, like a change to the HTML.
Send a test
A test sends the template as it is saved now, published or not, with "[Test]" before the subject. A variable takes the value you give, then its default, and stays in the message as {{NAME}} when it has neither. It needs a subject and a message, and it is a real email that counts as one.
curl -X POST "$OPENSEND_API_URL/v1/templates/tmpl_06/test" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "to": "you@example.com", "from": "Acme <hello@mail.example.com>", "variables": { "NAME": "Ada" }}'To start a new template from an old one, copy it. The copy is a draft with a free alias.
curl -X POST "$OPENSEND_API_URL/v1/templates/tmpl_06/duplicate" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{}'Publish it
A new template is a draft and cannot be sent. Publishing makes the version you saved the one that is sent.
curl -X POST "$OPENSEND_API_URL/v1/templates/tmpl_02/publish" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{}'You can keep editing after that. Emails use the published version until you publish again, and changed is true while the saved version is newer than the published one.
Versions
Every publish that changes something is kept as a version, numbered from 1, and version on the template says how many there were. The last 50 are kept. Publishing what is already published makes no new version.
curl "$OPENSEND_API_URL/v1/templates/tmpl_06/versions" \ -H "Authorization: Bearer $OPENSEND_API_KEY"live marks the version emails are built from now. One version comes back with everything it holds: the subject, the HTML, the plain text, the sender, the reply address and the defaults.
curl "$OPENSEND_API_URL/v1/templates/tmpl_06/versions/1" \ -H "Authorization: Bearer $OPENSEND_API_KEY"Restoring a version copies it into the version you edit. What is sent stays as it is until you publish again, so you can look at it, change it or send a test first.
curl -X POST "$OPENSEND_API_URL/v1/templates/tmpl_06/versions/1/restore" \ -H "Authorization: Bearer $OPENSEND_API_KEY" \ -H "Content-Type: application/json" \ -d '{}'Send with it
Name the template by id or alias when you send, with a value for each variable. Sending email shows the request.
template_missing: there is no published template with that id or alias.template_variable_missing: a variable has no value and no default. The message names it.email_no_sender: neither the send nor the template names a sender.alias_taken: the workspace already has a template with that alias.template_designed:htmlortextwas sent to a template built from blocks.template_written:templates.editwas sent to a template written as HTML. Give it adesignwithtemplates.updatefirst.