Documentation
DocsCore ConceptsTemplates
Templates
Reusable email templates with Liquid variable syntax. Templates support versioning and can be previewed before sending.
Template Schema
Template
{
id: string,
name: string,
subject: string, // supports Liquid: "Welcome {{ contact.fullName }}"
html?: string, // HTML body (supports Liquid)
text?: string, // plaintext body (supports Liquid)
status: "active" | "draft" | "paused" | "failed" | "archived",
version: number,
updatedAt: string
}When creating or updating templates, you can use
body as an alias for text. If both are provided, text takes precedence.Liquid Variables
Templates use Liquid syntax. The following variables are available at render time:
Available Liquid Variables
{{ contact.fullName }} // contact full name
{{ contact.email }} // contact email address
{{ contact.attributes.<key> }} // custom contact attributes (e.g. {{ contact.attributes.company }})
{{ organization.name }} // your organization name
{{ vars.<key> }} // per-enrollment variables passed at enrollment time
{{ unsubscribe_text }} // opt-out text (populated when optOutMode is "reply")Creating Templates
TypeScript
const template = await client.createTemplate({
name: "Welcome Email",
subject: "Welcome to {{ organization.name }}, {{ contact.fullName }}!",
html: "<h1>Welcome!</h1><p>Hi {{ contact.attributes.firstName }}, thanks for signing up.</p>",
body: "Hi {{ contact.attributes.firstName }}, thanks for signing up."
});curl
curl -X POST https://api.outreachagent.dev/v1/templates \
-H "Authorization: Bearer $OUTREACHAGENT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Welcome Email",
"subject": "Welcome to {{ organization.name }}, {{ contact.fullName }}!",
"body": "Hi {{ contact.attributes.firstName }}, thanks for signing up."
}'Previewing Templates
Use the preview endpoint to render a template with variables and catch missing values before sending:
TypeScript
const preview = await client.previewTemplate("tmpl_abc123", {
contact: { fullName: "Jane Doe", attributes: { firstName: "Jane" } },
organization: { name: "Acme Corp" }
});
console.log(preview.subject); // "Welcome to Acme Corp, Jane Doe!"
console.log(preview.html); // rendered HTML
console.log(preview.missingVariables); // [] (empty = all variables filled)curl
curl -X POST https://api.outreachagent.dev/v1/templates/tmpl_abc123/preview \
-H "Authorization: Bearer $OUTREACHAGENT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"variables": {"contact": {"fullName": "Jane Doe", "attributes": {"firstName": "Jane"}}, "organization": {"name": "Acme Corp"}}}'TemplatePreview Response
{
subject: string, // rendered subject
html: string, // rendered HTML body
missingVariables: string[] // variables referenced but not provided
}