Skip to content
Pidgely Docs

Guides

Templates

Store email content once with typed variables and fallbacks, edit drafts safely, publish versions and send with template id or alias.

View as Markdown

A template holds the subject, HTML, text and (optionally) sender of an email, with variables filled in at send time. Templates have a draft you can edit freely and published versions that sends use, so editing never changes what goes out until you publish.

Create a template

Node.js
import { Pidgely } from 'pidgely';

const pidgely = new Pidgely(process.env.PIDGELY_API_KEY);

const { data, error } = await pidgely.templates.create({
  name: 'Order confirmation',
  alias: 'order-confirmation',
  from: 'Acme <orders@acme.com>',
  subject: 'Order {{{ORDER_ID}}} confirmed',
  html: '<p>Hi {{{CUSTOMER_NAME|there}}}, your order {{{ORDER_ID}}} totals ${{{TOTAL}}}.</p>',
  variables: [
    {
      key: 'ORDER_ID',
      type: 'string',
    },
    {
      key: 'TOTAL',
      type: 'number',
      fallbackValue: 0,
    },
    {
      key: 'CUSTOMER_NAME',
      type: 'string',
      fallbackValue: 'there',
    },
  ],
});
console.log(data ?? error);
Python
import os
import pidgely

pidgely.api_key = os.environ["PIDGELY_API_KEY"]

result = pidgely.Templates.create({
    "name": "Order confirmation",
    "alias": "order-confirmation",
    "from": "Acme <orders@acme.com>",
    "subject": "Order {{{ORDER_ID}}} confirmed",
    "html": "<p>Hi {{{CUSTOMER_NAME|there}}}, your order {{{ORDER_ID}}} totals ${{{TOTAL}}}.</p>",
    "variables": [
        {
            "key": "ORDER_ID",
            "type": "string",
        },
        {
            "key": "TOTAL",
            "type": "number",
            "fallback_value": 0,
        },
        {
            "key": "CUSTOMER_NAME",
            "type": "string",
            "fallback_value": "there",
        },
    ],
})
print(result)
PHP
<?php

require __DIR__ . '/vendor/autoload.php';

$pidgely = Pidgely::client(getenv('PIDGELY_API_KEY'));

$result = $pidgely->templates->create([
    'name' => 'Order confirmation',
    'alias' => 'order-confirmation',
    'from' => 'Acme <orders@acme.com>',
    'subject' => 'Order {{{ORDER_ID}}} confirmed',
    'html' => '<p>Hi {{{CUSTOMER_NAME|there}}}, your order {{{ORDER_ID}}} totals ${{{TOTAL}}}.</p>',
    'variables' => [
        [
            'key' => 'ORDER_ID',
            'type' => 'string',
        ],
        [
            'key' => 'TOTAL',
            'type' => 'number',
            'fallback_value' => 0,
        ],
        [
            'key' => 'CUSTOMER_NAME',
            'type' => 'string',
            'fallback_value' => 'there',
        ],
    ],
]);
var_dump($result);
Go
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/pidgely/pidgely-go"
)

func main() {
	ctx := context.Background()
	client := pidgely.NewClient(os.Getenv("PIDGELY_API_KEY"))

	result, err := client.Templates.Create(ctx, &pidgely.CreateTemplateRequest{
		Name:    "Order confirmation",
		Alias:   "order-confirmation",
		From:    "Acme <orders@acme.com>",
		Subject: "Order {{{ORDER_ID}}} confirmed",
		Html:    "<p>Hi {{{CUSTOMER_NAME|there}}}, your order {{{ORDER_ID}}} totals ${{{TOTAL}}}.</p>",
		Variables: []pidgely.TemplateVariableInput{
			{
				Key:  "ORDER_ID",
				Type: "string",
			},
			{
				Key:           "TOTAL",
				Type:          "number",
				FallbackValue: 0,
			},
			{
				Key:           "CUSTOMER_NAME",
				Type:          "string",
				FallbackValue: "there",
			},
		},
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(result)
}
Ruby
require "pidgely"

Pidgely.api_key = ENV["PIDGELY_API_KEY"]

result = Pidgely::Templates.create({
  name: "Order confirmation",
  alias: "order-confirmation",
  from: "Acme <orders@acme.com>",
  subject: "Order {{{ORDER_ID}}} confirmed",
  html: "<p>Hi {{{CUSTOMER_NAME|there}}}, your order {{{ORDER_ID}}} totals ${{{TOTAL}}}.</p>",
  variables: [
    {
      key: "ORDER_ID",
      type: "string"
    },
    {
      key: "TOTAL",
      type: "number",
      fallback_value: 0
    },
    {
      key: "CUSTOMER_NAME",
      type: "string",
      fallback_value: "there"
    }
  ]
})
puts result
cURL
curl -X POST 'https://api.pidgely.com/templates' \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Order confirmation",
  "alias": "order-confirmation",
  "from": "Acme <orders@acme.com>",
  "subject": "Order {{{ORDER_ID}}} confirmed",
  "html": "<p>Hi {{{CUSTOMER_NAME|there}}}, your order {{{ORDER_ID}}} totals ${{{TOTAL}}}.</p>",
  "variables": [
    {
      "key": "ORDER_ID",
      "type": "string"
    },
    {
      "key": "TOTAL",
      "type": "number",
      "fallback_value": 0
    },
    {
      "key": "CUSTOMER_NAME",
      "type": "string",
      "fallback_value": "there"
    }
  ]
}'
  • name (1–200 characters) and html are required. from and reply_to are validated as addresses when present.
  • alias is an optional, unique, human-readable key (^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$, not shaped like a UUID). Every endpoint accepts the id or the alias. A duplicate alias gets 409 alias_taken.
  • The number of templates depends on the plan; see Template limits.

Variables

Variables use triple braces in subject, html and text:

Syntax Result
{{{ORDER_ID}}} The value passed at send time (or the declared fallback)
{{{CUSTOMER_NAME|there}}} The value, or there when none is available
{{ ORDER_ID }} Left as is (double braces are not variables)

Spaces inside the braces are allowed. In html, values are HTML-escaped; in subject and text they are inserted as is.

Declare up to 50 variables with a key (^[A-Za-z0-9_]{1,50}$), a type (string or number) and an optional fallback_value of that type. The names FIRST_NAME, LAST_NAME, EMAIL and UNSUBSCRIBE_URL are reserved.

Drafts and publishing

  1. Every create or update changes the draft and sets has_unpublished_versions: true.
  2. POST /templates/{id}/publish turns the draft into an immutable published version.
  3. Sends always use the latest published version. A template that was never published can't be used (template.id: only published templates can be used to send).

Duplicate creates a draft copy named <name> (copy), handy for A/B variants.

Template limits

Each organization can have a number of templates that depends on its plan (plans):

Plan Templates
Free 3
Starter 50
Growth 200
Scale Unlimited
  • The limit applies when you create a template (dashboard or POST /templates) and when you duplicate one. At the limit, the API answers 403 validation_error with field: "templates" and the message your plan allows 3 template(s); upgrade to create more.
  • Order e-mail designs customized for a store do not count and are never blocked by the limit.
  • Deleting a template frees a place. After a downgrade, templates above the new limit keep working: you can still edit, publish and send them; only new ones are refused until you are under the limit.
  • GET /me returns the limit in organization.max_templates and GET /dashboard/usage returns templates (the templates that count) and max_templates; null means unlimited. In the dashboard, the Templates list shows how many you have of the limit, and New template and Duplicate are disabled at the limit, with a link to upgrade.

Send with a template

JSON
{
  "to": ["steve@example.com"],
  "template": {
    "id": "order-confirmation",
    "variables": { "ORDER_ID": "1234", "TOTAL": 59.9, "CUSTOMER_NAME": "Steve" }
  }
}
  • template.id takes the id or the alias.
  • template can't be combined with html or text: the template's bodies are always used.
  • from, subject and reply_to come from the template only when the request leaves them empty: values in the request win.
  • Each variable resolves to the value you pass, then the declared fallback_value, then the inline |fallback. If any is still missing, the send fails with 422 validation_error and template.variables: missing value for ORDER_ID.
  • String values can be up to 2,000 characters; numbers are formatted as given. A string passed to a number variable fails with must be a number. Keys you didn't declare are treated as strings.

Templates work in batch sends too, each email with its own variables.

Languages and automatic translation

One template can hold the same e-mail in several languages. It has a base language (the language you write it in) and language variants: each has its own subject, preview text and content (builder document or HTML) and text version, while the variables, From and Reply-To are shared. Every send picks the right language for its recipient, so you keep one template, one alias and one set of variables instead of welcome-en, welcome-pt-br, welcome-es.

In the dashboard, the language switcher in the builder's top bar lists the original and each language. Add language offers two ways to start:

  • Translate automatically (Scale plan): AI translates the subject, preview text and every block of the original, keeping the layout, styles, links, variables and HTML blocks exactly as they are. You then edit the result visually, like any template. It uses the AI assist quota.
  • Translate by hand (every plan): the language starts as a copy of the original for you to rewrite.

When you change the words, links or blocks of the original after a language was translated, that language is marked Out of date in the switcher and in the bar above the e-mail. Update translation translates the original again (on Scale); Update all does it for every out-of-date language at once; Mark as up to date clears the flag when you have checked it yourself. Changing only colors, fonts or spacing does not make a translation out of date, and the theme (colors, fonts, logo) is always shared by every language.

Languages are part of the draft and are published together with the template: a send always uses the languages of the latest published version. Removing a language takes effect on the next publish.

Supported languages: en, en-gb, pt-br, pt-pt, es, es-419, es-mx, fr, fr-ca, de, it, nl, pl, sv, da, nb, fi, cs, ro, hu, el, tr, ru, uk, ar, he, hi, id, vi, th, ja, ko, zh-cn and zh-tw, up to 20 per template. Codes are case-insensitive and _ works as - (pt_BR is pt-br).

Which language a send uses

  1. template.locale in the send request, when present.
  2. Otherwise, the language property of the recipient's contact (the first to address), when there is one.
  3. Otherwise, the base language.

A requested language falls back step by step: the exact code (pt-br), then its primary language (es-MX uses es), then the base when it is the same language, then another variant of the same language (pt uses pt-br), and finally the base. A locale that is not a language tag is rejected with 422 validation_error (template.locale); a contact language that is not one is ignored.

The e-mail records the language it was sent in: GET /emails/{id} returns "template": { "id": "…", "locale": "pt-br" } (a Pidgely extension), and the e-mail page in the dashboard shows it.

Languages through the API

Set the base language with language when you create or update a template. Retrieve returns language and languages (each with locale, source ai or manual, stale and timestamps); the content of each language is under /templates/{id}/languages:

cURL
curl -X POST 'https://api.pidgely.com/templates/order-confirmation/languages/es/translate' \
  -H "Authorization: Bearer $PIDGELY_API_KEY"
  • Translate translates the current draft of the base into a language and stores it (created or replaced, up to date). It needs a builder template and AI assist (403 plan_required below Scale), and counts against the AI quota.
  • Set a language (PUT /templates/{id}/languages/{locale}) creates or replaces one by hand, on every plan. A new language starts as a copy of the base, so send only what differs (subject, builder, or html and text); "up_to_date": true marks it as matching the current base.
  • List, retrieve and remove a language; languages on create and update replaces them all at once.
  • Publish the template to send the changes.
cURL
curl -X PUT 'https://api.pidgely.com/templates/order-confirmation/languages/pt-br' \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "subject": "Pedido {{{ORDER_ID}}} confirmado"
}'

Visual builder and AI assist

On every plan, Free included, the dashboard has a visual template builder: drag-and-drop blocks edited in place on the e-mail itself, a live preview on desktop, phone and in dark mode, deliverability checks and brand import. On the Scale plan, AI assist also writes an email from a prompt, rewrites a block, translates the template into other languages and suggests subject lines. AI requests below Scale get 403 plan_required.

New template opens the builder directly, with the From, Subject and preview text at the top, edited inline like in an e-mail client. To write the HTML yourself, use Start with HTML next to it: the same full-screen workspace opens in HTML mode, with the code editor and the live preview side by side, deliverability checks, send test and publish. The … menu switches between the two: Edit HTML in the builder turns the template into an HTML template, and Open in the visual builder in HTML mode goes the other way.

Templates created through the API with html open in the builder too. When nothing would be lost, the HTML is converted to blocks; otherwise it is placed in a single HTML block. Either way, the e-mail that is sent stays the same until you edit it.

A builder template stores a block document next to its HTML. Pidgely renders the document on the server into email HTML built for real inboxes: table layout with inline CSS, Outlook-safe (VML) buttons, columns that stack on phones, dark-mode rules and a hidden preview text, plus a plain-text version. Sends, batch sends and preview use that HTML, so a builder template is sent exactly like any other template.

Through the API, pass the document as builder (a Pidgely extension to the Resend shape) instead of html:

JSON
{
  "name": "October update",
  "subject": "What shipped in October, {{{FIRST_NAME|there}}}",
  "builder": {
    "version": 1,
    "preview_text": "Faster dashboards and a new reporting API",
    "theme": { "brand_color": "#e2793f", "font": "inter", "content_width": 600 },
    "blocks": [
      { "type": "heading", "level": 1, "text": "What shipped in October" },
      { "type": "text", "runs": [
        { "text": "Hi {{{FIRST_NAME|there}}}, dashboards now load " },
        { "text": "twice as fast", "bold": true },
        { "text": "." }
      ] },
      { "type": "button", "label": "See what is new", "href": "https://acme.com/changelog" },
      { "type": "footer", "runs": [{ "text": "Acme · Rua Augusta 1500 · São Paulo" }], "unsubscribe": true }
    ]
  }
}
  • Block types: heading, text, button, image, divider, spacer, columns (2 or 3, not nested), list, quote, code, social, footer and html. Each block may have a style with align, color, background, font_size and padding.
  • Text is plain strings and runs (bold, italic, href); only the html block carries markup, and every other block rejects it. Links accept https, http, mailto, tel or a variable tag; anything else (javascript:, data:, relative paths) is rejected with a field error such as builder.blocks[2].href: must use https, http, mailto or tel.
  • The template's html and text are rendered from the document. GET returns the document as builder (null for HTML templates).
  • Sending html without builder turns a builder template into an HTML template; "builder": null does the same and keeps the last HTML.
  • A footer with unsubscribe links to {{{PIDGELY_UNSUBSCRIBE_URL}}}. Broadcasts fill it per recipient; on API sends, pass it in template.variables (or declare it as a variable with a fallback URL).

HTML blocks

The HTML block holds raw HTML you write yourself. The builder shows it as-is on the canvas (sandboxed) and edits it in a code editor in the side panel. In a document it goes in blocks, or inside columns, like any other block:

JSON
{ "type": "html", "html": "<table role=\"presentation\" width=\"100%\"><tr><td>Hi {{{FIRST_NAME|there}}}, your invoice is ready.</td></tr></table>" }
  • The HTML is sent verbatim. Variable tags such as {{{FIRST_NAME|there}}} are filled at send time like everywhere else, with values HTML-escaped. Each block holds at most 256 KB.
  • When an HTML block is the only block and holds a complete document (<html>, <body> or a doctype), it is the e-mail: it is rendered verbatim, without the builder's layout and theme, and the preview text, if set, is inserted right after <body>.
  • Otherwise it is a fragment, placed in the e-mail card like any other block. A complete document in that position contributes its <style> rules and the content of its body.
  • The plain-text version is derived from the HTML, and the deliverability checks (spam phrases, links, missing alt text, unsubscribe link, size) still run on it.
  • AI assist never writes or rewrites HTML blocks; translation keeps them unchanged.

AI assist sends only the prompt and the template being edited to the model, never contact data, and each organization has a monthly AI request quota and a per-minute limit (429 ai_quota_exceeded / ai_rate_limited).

Builder and AI through the API

Everything the dashboard builder does is also on the API for full_access keys, with the same AI plan and quota (reference): the builder routes (render, convert, theme, brand import) work on every plan, and only the /template-builder/ai/... routes need Scale. Capabilities report ai_available and the cheapest plan with AI assist in ai_required_plan; builder (always true) and required_plan (free) are kept for compatibility. Check what the organization can use, then generate an e-mail with your theme and brand:

Node.js
import { Pidgely } from 'pidgely';

const pidgely = new Pidgely(process.env.PIDGELY_API_KEY);

const { data, error } = await pidgely.templateBuilder.ai.generate({
  prompt: 'Welcome e-mail for new users of our invoicing app, with one call to action to create the first invoice',
  language: 'en',
});
console.log(data ?? error);
cURL
curl -X POST 'https://api.pidgely.com/template-builder/ai/generate' \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "prompt": "Welcome e-mail for new users of our invoicing app, with one call to action to create the first invoice",
  "language": "en"
}'

The response has a subject, a preview_text and a document: save it with Create a template as builder. Render returns the exact HTML a send would use plus deliverability issues, without saving anything; rewrite, translate and subject suggestions work on documents the same way, and convert turns simple HTML into a document when nothing would be lost (otherwise, put the HTML in an HTML block).

Node.js
import { Pidgely } from 'pidgely';

const pidgely = new Pidgely(process.env.PIDGELY_API_KEY);

const { data, error } = await pidgely.templateBuilder.render({
  document: {
    blocks: [
      {
        type: 'heading',
        text: 'Welcome, {{{FIRST_NAME|there}}}',
      },
      {
        type: 'button',
        label: 'Get started',
        href: 'https://acme.com/start',
      },
    ],
  },
  subject: 'Welcome to Acme',
});
console.log(data ?? error);
cURL
curl -X POST 'https://api.pidgely.com/template-builder/render' \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "document": {
    "blocks": [
      {
        "type": "heading",
        "text": "Welcome, {{{FIRST_NAME|there}}}"
      },
      {
        "type": "button",
        "label": "Get started",
        "href": "https://acme.com/start"
      }
    ]
  },
  "subject": "Welcome to Acme"
}'

Import your brand from your website

On every plan, the builder can read your website and set the theme for you. The first time you open the builder, paste your site (Pidgely suggests the root of your verified sending domain), then review the result before applying it. It is also in the builder's Theme panel and, on Scale, in the Write with AI dialog.

Pidgely looks for:

  • Logo: the header logo, logo images and inline SVG, the apple-touch-icon and other icons, the web app manifest, the Organization.logo of JSON-LD and the share image. Each candidate is measured (size, transparency, whether it reads on a light and on a dark background) and the wide, transparent header logo is preferred. Logos are stored by Pidgely and served from a permanent https://api.pidgely.com/files/brand/... URL, because e-mails need absolute image URLs. WebP and icon files are converted to PNG; SVG logos are sanitized (scripts, event handlers and external references removed) but flagged, because Gmail and Outlook do not display SVG.
  • Colors: theme-color, the manifest colors, brand-named CSS variables (--primary, --brand, --accent, shadcn/ui and Tailwind formats included), the colors of your primary buttons and links in your stylesheets, and the dominant colors of the logo. They are ranked into a brand color, links, text and page background. The button label is white or near-black, whichever passes WCAG AA (4.5:1) on your brand color, and links are darkened when needed to stay readable on white.
  • Fonts: the body and heading families from your CSS, Google Fonts links and @font-face. Google Fonts are linked in the e-mail for inboxes that support web fonts (Apple Mail, iOS, Thunderbird); every other inbox shows the closest e-mail-safe stack.
  • Identity: your company name, social profiles from the footer and JSON-LD (X, LinkedIn, Instagram, GitHub, YouTube, Facebook, TikTok, Discord) and your postal address. AI assist writes footers with them.

When AI assist is available (Scale), Claude picks the most coherent palette and logo among what was found and explains the choice; it only receives the extracted candidates, never the page itself, and the import works the same without it. Nothing changes until you apply.

Through the API:

Shell
curl -X POST https://api.pidgely.com/brand/import \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://acme.com", "apply": true}'

The response (reference) lists every candidate and the proposed theme and brand. With "apply": true they become the organization defaults used by new builder templates and AI assist.

The theme gains these optional fields, which you can also set by hand:

Field What it does
button_text_color Label color of buttons on the brand color (empty picks white or near-black automatically).
web_font, heading_web_font Google Fonts families for text and headings; font and heading_font are the fallback stacks.
logo_dark_url A logo variant shown by inboxes in dark mode (Apple Mail, iOS); the others keep logo_url.

Imports only reach public addresses: private and internal networks, other ports than 80 and 443, and redirects to them are refused (422 brand_url_forbidden); a site that cannot be read returns 422 brand_fetch_failed. Each organization can run 6 imports per minute.

The Brand page

The dashboard's Brand page (under Marketing, also linked from Settings and from the builder's Theme panel) is where the brand lives: the logo for light inboxes and the variant for dark mode, the brand color with its button label (the WCAG contrast is checked as you pick), links, text and background colors, the text and heading fonts with their Google Fonts, and the footer identity: company name, website, postal address and social links. A live preview shows a sample e-mail exactly as the server renders it for sending, in light and dark mode. Import from website runs the import again (prefilled with your website, or the domain you send from) and opens the same review before anything changes.

The brand logo is also the organization logo in the dashboard (organization switcher, Settings), on a tile it reads on: the dark-mode variant on a dark tile when there is one, otherwise the logo on white. Admins can upload another image or pick one of the brand logos, on the Brand page or in Settings, and go back to the brand logo at any time.

Automatic import when you add a domain

When an organization adds a sending domain and has not saved a brand yet, Pidgely reads the website of the domain's registrable parent in the background: send.acme.com reads https://acme.com/, mail.acme.com.br reads https://acme.com.br/ (the public suffix list decides where the parent starts), then https://www.acme.com/ if needed. It works like the import above, with the same safeguards, and without AI on every plan.

  • If a logo or brand colors are found and nothing is saved yet, the brand becomes the organization theme, marked as imported automatically. The Brand page says We imported your brand from acme.com, with the review card to adjust it; Looks good keeps it as it is. The domain page links to it.
  • A brand you saved yourself is never replaced. If one appears while the import runs, the result is kept for you to review instead.
  • If the site cannot be read, the Brand page says why: no_site (no answer, DNS, HTTP error or not a web page), blocked (a private address), timeout, or nothing_found (a page without logo or brand colors). Import from another address, or set the brand up by hand.

There is one attempt per organization and parent domain; adding news.acme.com after send.acme.com starts nothing new. Through the API, GET /brand (reference) returns the theme and profile, their state (none, auto for an automatic import waiting for review, or saved) and the latest automatic import with its status and reason; POST /brand/auto-import/dismiss (reference) hides the notice and keeps an automatic brand as reviewed.