Skip to main content
POST
/
templates
import { Emailr } from 'emailr';

const emailr = new Emailr('em_xxxxxxxxx');

const { data, error } = await emailr.templates.create({
  name: 'order-confirmation',
  html: '<p>Name: {{{PRODUCT}}}</p><p>Total: {{{PRICE}}}</p>',
  variables: [
    {
      key: 'PRODUCT',
      type: 'string',
      fallbackValue: 'item',
    },
    {
      key: 'PRICE',
      type: 'number',
      fallbackValue: 25,
    }
  ],
});

// Or create and publish a template in one step
await emailr.templates.create({ ... }).publish();
{
  "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
  "object": "template"
}
POST https://api.emailr.dev/templates

Body Parameters

name
string
required
The name of the template.
html
string
required
The HTML version of the template.
alias
string
The alias of the template.
from
string
Sender email address.To include a friendly name, use the format "Your Name <[email protected]>".If provided, this value can be overridden when sending an email using the template.
subject
string
Default email subject.This value can be overridden when sending an email using the template.
text
string
The plain text version of the message.
If not provided, the HTML will be used to generate a plain text version. You can opt out of this behavior by setting value to an empty string.
react
React.ReactNode
The React component used to write the template. Only available in the Node.js SDK.
variables
array
The array of variables used in the template. Each template may contain up to 50 variables.Each variable is an object with the following properties:
Before you can use a template, you must publish it first. To publish a template, use the Templates dashboard or publish template API.Learn more about Templates.
import { Emailr } from 'emailr';

const emailr = new Emailr('em_xxxxxxxxx');

const { data, error } = await emailr.templates.create({
  name: 'order-confirmation',
  html: '<p>Name: {{{PRODUCT}}}</p><p>Total: {{{PRICE}}}</p>',
  variables: [
    {
      key: 'PRODUCT',
      type: 'string',
      fallbackValue: 'item',
    },
    {
      key: 'PRICE',
      type: 'number',
      fallbackValue: 25,
    }
  ],
});

// Or create and publish a template in one step
await emailr.templates.create({ ... }).publish();
{
  "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
  "object": "template"
}