Create a template

Create a reusable server-side template.

Create a template with Mustache-style merge tags in the subject and body. The response returns the template id to pass as template 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.
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 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 "@wemail/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>",
  },
});
Python
from wemail.client import WemailClient
from wemail.api.templates_api import TemplatesApi
from wemail.models.create_template_request import CreateTemplateRequest

wemail = WemailClient(api_key=os.environ["WEMAIL_API_KEY"])
# .templates isn't on the flat facade yet — reuse its configured HTTP client.
templates = TemplatesApi(wemail.messages.api_client)

template = templates.create_template(CreateTemplateRequest(
    name="Welcome email",
    subject="Welcome, {{name}}!",
    html="<h1>Welcome, {{name}}!</h1><p>Thanks for joining.</p>",
))
PHP
<?php
$wemail = new \Wemail\WemailClient(getenv('WEMAIL_API_KEY'));
// .templates() isn't on the flat facade yet — reuse its configured HTTP config.
$templates = new \Wemail\Sdk\Api\TemplatesApi(null, $wemail->messages()->getConfig());
$template = $templates->createTemplate(new \Wemail\Sdk\Model\CreateTemplateRequest([
    'name'    => 'Welcome email',
    'subject' => 'Welcome, {{name}}!',
    'html'    => '<h1>Welcome, {{name}}!</h1>',
]));
Ruby
wemail = Wemail::Client.new(api_key: ENV["WEMAIL_API_KEY"])
# .templates isn't on the flat facade yet — reuse its configured HTTP client.
templates = Wemail::TemplatesApi.new(wemail.messages.api_client)
template = templates.create_template(Wemail::CreateTemplateRequest.new(
  name: "Welcome email",
  subject: "Welcome, {{name}}!",
  html: "<h1>Welcome, {{name}}!</h1>"
))
Go
client, err := wemail.NewClient(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"));
// .templates() isn't on the flat facade yet — reuse its configured ApiClient.
TemplatesApi templates = new TemplatesApi(wemail.apiClient());
Template tpl = 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"
}