Merge tags & variables
Personalise subjects and bodies with {{key}} merge tags in the wemail API: literal per-recipient substitution, HTML escaping, and a worked example.
Pass values via vars on a send, or global_vars plus per-recipient vars in a batch — they substitute into the subject, HTML and text body. This works with a stored template (template_id) and with inline subject / html / text alike.
Syntax
There is one construct: {{key}}. Every occurrence of {{key}} is replaced with the value of key from vars. It is a literal text replacement, not a template language — there are no conditionals, loops, filters or default values.
| Parameter | Type | Required | Description |
|---|---|---|---|
{{key}} | substitution | Optional | Replaced with the value of key, converted to text (numbers and booleans as written, e.g. 42.1, true). Keys are matched exactly and are case-sensitive; write the tag without spaces inside the braces ({{ key }} is not recognised). |
Unmatched tags | left as written | Optional | A {{tag}} with no matching key in vars stays in the email exactly as written. Supply every key your content uses (in a batch, put shared keys in global_vars). |
Escaping | HTML body only | Optional | Values substituted into the HTML body are HTML-escaped (<, >, &, ", '), so a value can never inject markup. Values in the subject and text body are inserted as-is. |
Batch precedence | recipient wins | Optional | In POST /v3/messages.batch, recipients[].vars are merged over global_vars; on a matching key the recipient’s value is used. |
Example
{
"from": "you@yourdomain.com",
"to": [
"alex@example.com"
],
"subject": "Hi {{first_name}}, your balance is {{balance}}",
"html": "<p>Hi {{first_name}},</p>\n<p>Your balance is {{balance}}.</p>\n<p>{{plan_note}}</p>",
"text": "Hi {{first_name}}, your balance is {{balance}}. {{plan_note}}",
"vars": {
"first_name": "Alex",
"balance": "€42.10",
"plan_note": "Thanks for being a premium member!"
}
}With those vars, {{first_name}} renders as Alex, {{balance}} as €42.10 and {{plan_note}} as the sentence you supplied, in the subject, HTML and text alike. Had plan_note been missing from vars, the email would show the literal text {{plan_note}} — send an empty string ("plan_note": "") to leave it blank.
Code examples
curl -X POST https://api.wemail.io/v3/messages \
-H "Authorization: Bearer afn_live_pK7…b9aF" \
-H "Content-Type: application/json" \
-d '{
"from": "noreply@updates.acme.io",
"to": ["alex@example.com"],
"subject": "Hi {{first_name}}, your balance is {{balance}}",
"html": "<p>Hi {{first_name}},</p><p>Your balance is {{balance}}.</p>",
"vars": { "first_name": "Alex", "balance": "$42.10" }
}'import { WemailClient } from "@wemailio/sdk";
const wemail = new WemailClient(process.env.WEMAIL_API_KEY);
await wemail.sendMessage({
from: "noreply@updates.acme.io",
to: ["alex@example.com"],
subject: "Hi {{first_name}}, your balance is {{balance}}",
html: "<p>Hi {{first_name}},</p><p>Your balance is {{balance}}.</p>",
vars: { first_name: "Alex", balance: "$42.10" },
});import os
from wemail import WemailClient
wemail = WemailClient(api_key=os.environ["WEMAIL_API_KEY"])
wemail.send_message({
"from": "noreply@updates.acme.io",
"to": ["alex@example.com"],
"subject": "Hi {{first_name}}, your balance is {{balance}}",
"html": "<p>Hi {{first_name}},</p><p>Your balance is {{balance}}.</p>",
"vars": {"first_name": "Alex", "balance": "$42.10"},
})<?php
$wemail = new \Wemail\WemailClient(getenv('WEMAIL_API_KEY'));
$wemail->sendMessage([
'from' => 'noreply@updates.acme.io',
'to' => ['alex@example.com'],
'subject' => 'Hi {{first_name}}, your balance is {{balance}}',
'html' => '<p>Hi {{first_name}}, your balance is {{balance}}.</p>',
'vars' => ['first_name' => 'Alex', 'balance' => '$42.10'],
]);wemail = Wemail::Client.new(api_key: ENV["WEMAIL_API_KEY"])
wemail.send_message(
from: "noreply@updates.acme.io",
to: ["alex@example.com"],
subject: "Hi {{first_name}}, your balance is {{balance}}",
html: "<p>Hi {{first_name}}, your balance is {{balance}}.</p>",
vars: { first_name: "Alex", balance: "$42.10" }
)client, err := wemail.NewClient(os.Getenv("WEMAIL_API_KEY"))
client.SendMessage(wemail.SendMessageRequest{
From: "noreply@updates.acme.io",
To: []string{"alex@example.com"},
Subject: "Hi {{first_name}}, your balance is {{balance}}",
Html: wemail.PtrString("<p>Hi {{first_name}}, your balance is {{balance}}.</p>"),
Vars: map[string]interface{}{"first_name": "Alex", "balance": "$42.10"},
})WemailClient wemail = new WemailClient(System.getenv("WEMAIL_API_KEY"));
wemail.sendMessage(new SendMessageRequest()
.from("noreply@updates.acme.io")
.to(List.of("alex@example.com"))
.subject("Hi {{first_name}}, your balance is {{balance}}")
.html("<p>Hi {{first_name}}, your balance is {{balance}}.</p>")
.vars(Map.of("first_name", "Alex", "balance", "$42.10")));var wemail = new WemailClient(Environment.GetEnvironmentVariable("WEMAIL_API_KEY"));
await wemail.SendMessageAsync(new SendMessageRequest(
from: "noreply@updates.acme.io",
to: new List<string> { "alex@example.com" },
subject: "Hi {{first_name}}, your balance is {{balance}}",
html: "<p>Hi {{first_name}}, your balance is {{balance}}.</p>",
vars: new Dictionary<string, object> { ["first_name"] = "Alex", ["balance"] = "$42.10" }));{
"id": "msg_01HBYE7K9Z4PMQDR3W",
"status": "queued",
"created_at": "2026-05-10T09:42:18Z",
"to": ["alex@example.com"]
}