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
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Required | Human-readable template name (max 255 chars). HTML is stripped. |
description | string | Optional | What the template is for (max 1000 chars). Shown in the Console. |
subject | string | Optional | Subject line (max 998 chars); supports merge tags like {{name}}. Overrides the send's inline subject when the template is used. |
html | string | Optional | HTML body; supports merge tags. Sanitized on save — scripts, embedded frames, event handlers and non-HTTPS image URLs are removed or rejected. |
text_body | string | Optional | Plain-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_schema | object | Optional | Declares the variables the template expects (name → type hint). Documentation only — not enforced on send. |
category | string | Optional | Free-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
| Status | Description |
|---|---|
201 | Created. The new template, with version: 1 and active: true. |
400 | Validation error, or the HTML references a blocked (non-allowed) image URL. |
401 | Missing 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 sendMessagePython
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_messagePHP
<?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.idGo
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"
}