Create a template

Create a reusable server-side template with the wemail API: subject, HTML and text bodies with merge tags, versioned so later edits never break live sends.

Create a template with {{key}} merge tags in the subject and body (literal replacement from the send's vars — see Merge tags & variables). The response returns the template id to pass as template_id on POST /v3/messages.

POST /v3/templates

Body parameters

ParameterTypeRequiredDescription
namestringRequiredHuman-readable template name (max 255 chars). HTML is stripped.
descriptionstringOptionalWhat the template is for (max 1000 chars). Shown in the Console.
subjectstringOptionalSubject line (max 998 chars); supports merge tags like {{name}}. Overrides the send's inline subject when the template is used.
htmlstringOptionalHTML body; supports merge tags. Sanitized on save — scripts, embedded frames, event handlers and non-HTTPS image URLs are removed or rejected.
text_bodystringOptionalPlain-text body rendered for text-only clients. text is accepted as an alias (the name POST /v3/messages uses); when both are sent, text_body wins.
vars_schemaobjectOptionalDeclares the variables the template expects (name → type hint). Documentation only — not enforced on send.
categorystringOptionalFree-form category (max 100 chars) used to filter GET /v3/templates.

New templates start at version: 1 with active: true. The response is the full template object — pass its id as template_id on POST /v3/messages.

Responses

StatusDescription
201Created. The new template, with version: 1 and active: true.
400Validation error, or the HTML references a blocked (non-allowed) image URL.
401Missing or invalid API key.

Code examples

cURL
curl -X POST https://api.wemail.io/v3/templates \
  -H "Authorization: Bearer afn_live_pK7…b9aF" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome email",
    "subject": "Welcome, {{name}}!",
    "html": "<h1>Welcome, {{name}}!</h1><p>Thanks for joining.</p>"
  }'
Node.js
import { WemailClient } from "@wemailio/sdk";
const wemail = new WemailClient(process.env.WEMAIL_API_KEY);

const template = await wemail.templates.createTemplate({
  createTemplateRequest: {
    name:      "Welcome email",
    subject:   "Welcome, {{name}}!",
    html:      "<h1>Welcome, {{name}}!</h1><p>Thanks for joining.</p>",
    varsSchema: { name: "string" },
  },
});
console.log(template.id); // pass as templateId on sendMessage
Python
import os
from wemail import WemailClient, CreateTemplateRequest

wemail = WemailClient(api_key=os.environ["WEMAIL_API_KEY"])

template = wemail.templates.create_template(CreateTemplateRequest(
    name="Welcome email",
    subject="Welcome, {{name}}!",
    html="<h1>Welcome, {{name}}!</h1><p>Thanks for joining.</p>",
    vars_schema={"name": "string"},
))
print(template.id)  # pass as template_id on send_message
PHP
<?php
$wemail = new \Wemail\WemailClient(getenv('WEMAIL_API_KEY'));
$template = $wemail->templates()->createTemplate(new \Wemail\Sdk\Model\CreateTemplateRequest([
    'name'    => 'Welcome email',
    'subject' => 'Welcome, {{name}}!',
    'html'    => '<h1>Welcome, {{name}}!</h1><p>Thanks for joining.</p>',
]));
echo $template->getId();
Ruby
wemail = Wemail::Client.new(api_key: ENV["WEMAIL_API_KEY"])
template = wemail.templates.create_template(Wemail::CreateTemplateRequest.new(
  name: "Welcome email",
  subject: "Welcome, {{name}}!",
  html: "<h1>Welcome, {{name}}!</h1><p>Thanks for joining.</p>"
))
puts template.id
Go
client, _ := wemail.NewClient(os.Getenv("WEMAIL_API_KEY"))
// Generated layer (client.API.*): pass the key in the context.
ctx := context.WithValue(context.Background(), wemail.ContextAccessToken, os.Getenv("WEMAIL_API_KEY"))
tpl, _, err := client.API.TemplatesAPI.CreateTemplate(ctx).
    CreateTemplateRequest(wemail.CreateTemplateRequest{
        Name:    "Welcome email",
        Subject: wemail.PtrString("Welcome, {{name}}!"),
        Html:    wemail.PtrString("<h1>Welcome, {{name}}!</h1>"),
    }).Execute()
Java
WemailClient wemail = new WemailClient(System.getenv("WEMAIL_API_KEY"));
Template tpl = wemail.templates().createTemplate(new CreateTemplateRequest()
    .name("Welcome email")
    .subject("Welcome, {{name}}!")
    .html("<h1>Welcome, {{name}}!</h1>"));
.NET
var wemail = new WemailClient(Environment.GetEnvironmentVariable("WEMAIL_API_KEY"));
var tpl = await wemail.Templates.CreateTemplateAsync(new CreateTemplateRequest(
  name: "Welcome email",
  subject: "Welcome, {{name}}!",
  html: "<h1>Welcome, {{name}}!</h1>"));
ResponseExample response
{
  "id": "tpl_01HCX9F2K7QW",
  "name": "Welcome email",
  "subject": "Welcome, {{name}}!",
  "version": 1,
  "created_at": "2026-05-10T09:42:18Z"
}