Skip to Content
API ReferenceEmail Templates API

Email Templates API

The Email Templates API lets administrators customize the transactional emails sent by Auris. Each of the thirteen template types corresponds to a specific event (verification, password reset, magic link, security alerts, …) and can be customized with HTML and dynamic variables, independently per locale, either for the whole tenant or for one application.

Breaking changes

  • DELETE /api/email-templates/{type} now requires the locale query parameter and resets only that locale. Without locale it returns 422; it no longer deletes every locale of the type.
  • PUT /api/email-templates/{type} returns 422 (previously 400) when subject or htmlBody is missing or invalid.
  • PUT defaults to action: "publish". Publishing runs a pre-publish check and returns 422 when it fails (unknown variables, a missing required link or code variable). Send action: "draft" to save incomplete work without publishing it. Optional conflict-check tokens return 409 when the document changed in another session.
  • defaultSubject and defaultHtmlBody in GET /api/email-templates/{type} now return the effective published template that a live send would use, not always the built-in template.
  • New applications default to emailTemplateInheritance: false and do not use the tenant’s custom templates. Applications that already existed in tenants with custom templates were migrated to true.
  • PATCH /api/email-templates/applications/{applicationId} requires admin:all.

Scope and delivery order

Templates belong either to the tenant or to one application. Pass the applicationId query parameter (or applicationId in the request body; if both are given they must match, otherwise 422) to work on an application’s templates. Without it, requests apply to the tenant’s templates. An unknown, inactive, or foreign application returns 404.

Auris ships with default templates for all types in five locales (en, it, fr, de, es). When an email is sent for an application, the template is resolved in this order:

  1. The application’s published template (requested locale, then en).
  2. The tenant’s published template (requested locale, then en), only when the application’s emailTemplateInheritance is true.
  3. The built-in default (requested locale, then en), rendered with the application’s or tenant’s branding.

Emails sent without an application use the tenant’s published template, then the built-in default. Drafts are never used for delivery.

All endpoints select the tenant via the x-tenant header (the tenant’s realm identifier) and require a Bearer token with the manage:security permission, except PATCH /api/email-templates/applications/{applicationId}, which requires admin:all.

These endpoints return plain JSON objects — they do not use the { ok, data } envelope found in other parts of the Auris API.

List Templates

GET/api/email-templatesRequires: manage:security

List all thirteen template types with their customization status for the tenant. Full HTML bodies are not included — fetch a single template for that.

Success response (200)

{ "templates": [ { "type": "verification", "label": "Email Verification", "description": "Sent when a new user registers to verify their email address.", "variables": ["email", "link", "expiresIn", "year", "month", "day", "date"], "hasCustomTemplate": true, "active": true, "updatedAt": "2026-07-20T10:00:00.000Z", "customLocales": ["en", "it"] } ], "applicationId": null, "availableLocales": ["en", "it", "fr", "de", "es"], "wellKnownLocales": { "en": "English", "it": "Italiano", "pt-BR": "Português (Brasil)" } }

The list covers the scope selected by applicationId (null for the tenant).

FieldTypeDescription
typestringTemplate type identifier (see Template Types below)
labelstringHuman-readable template name
descriptionstringWhen the email is sent
variablesstring[]Variables available for this type, including the auto-injected global date variables (year, month, day, date)
hasCustomTemplatebooleantrue if at least one custom version exists (any locale)
activebooleanWhether a custom version is active (true when no custom template exists — the default is always active)
updatedAtstring | nullISO 8601 timestamp of the most recent customization, or null
customLocalesstring[]Locales for which a custom version exists
availableLocalesstring[]Locales with built-in default templates
wellKnownLocalesobjectLocale code -> display label map used by the Console

Get Template

GET/api/email-templates/{type}?locale={locale}Requires: manage:security

Get a template for one locale: the custom content (if any) plus the branded default baseline. The locale query parameter defaults to en.

Success response (200)

{ "type": "verification", "locale": "it", "label": "Email Verification", "description": "Sent when a new user registers to verify their email address.", "variables": ["email", "link", "expiresIn", "year", "month", "day", "date"], "hasCustomTemplate": false, "subject": null, "htmlBody": null, "metadata": null, "active": true, "updatedAt": null, "defaultSubject": "Verifica il tuo indirizzo email", "defaultHtmlBody": "<!DOCTYPE html>...", "availableLocales": ["en", "it", "fr", "de", "es"], "customLocales": ["en"], "hasDefaultTemplate": true, "wellKnownLocales": { "en": "English", "it": "Italiano" } }

subject, htmlBody, and metadata are null when no custom template exists for the requested locale in the selected scope. defaultSubject and defaultHtmlBody contain the effective published template that a live send would use, following the delivery order above (application, then tenant when inheritance is on, then built-in). They fall back to the built-in template, rendered with the branding (logo, color, white-label footer) a live send would use, only when no published template applies. effectiveSource (application, tenant, or default) and effectiveLocale say where it came from. hasDefaultTemplate indicates whether the requested locale has a built-in default (en, it, fr, de, es); other locales fall back to English.

The response also includes the current draft (or null), the latest revisions, documentVersion, applicationId, tenantId, requiredVariables, textBody, emailTheme, and emailTemplateInheritance.

Error responses

HTTPDescription
400Invalid template type or invalid locale code
401 / 403Missing or insufficient permissions
404Tenant not found

Update Template

PUT/api/email-templates/{type}Requires: manage:security

Save a draft or publish the custom template for one locale. The locale can be passed in the body or as a query parameter; it defaults to en. Only a published template is used for delivery.

Request body

{ "subject": "Verify your email — {{email}}", "htmlBody": "<!DOCTYPE html><html><body><h1>Verify your email</h1><p>Hello {{email}},</p><p><a href=\"{{link}}\">Confirm your address</a></p><p>The link expires in {{expiresIn}}.</p></body></html>", "locale": "en", "metadata": { "source": "code" } }
FieldTypeRequiredDescription
subjectstringYesEmail subject line. May include {{variable}} placeholders. May be empty in a draft
htmlBodystringYesFull HTML email body. Maximum size 500 KB. May be empty in a draft
textBodystring | nullNoPlain-text alternative
localestringNoLocale code (BCP-47-like, e.g. en, pt-BR). Defaults to en
action"publish" | "draft"NoDefaults to "publish". "draft" saves the content without publishing it and without the pre-publish check
applicationIdstringNoApplication scope; same as the applicationId query parameter
metadataobjectNoEditor state used by the Console (theme, builder layout, source mode). Validated against a closed schema — unrecognized fields are rejected, not silently dropped. Maximum size 256,000 characters
expectedRevisionintegerNoConflict check: the draft revision the client last read (0 when there was no draft)
expectedDraftIdstring | nullNoConflict check: the draft id the client last read (null when there was no draft)
expectedDocumentVersionintegerNoConflict check: the documentVersion the client last read
expectedPublishedAtstring | nullNoConflict check (publish only): the published template’s updatedAt the client last read (null when none)

Publishing requires a non-empty subject and body, rejects unknown {{variables}}, and requires the type’s link or code variable (for example {{link}} for magic_link, {{code}} for mfa_code). Any conflict-check token that no longer matches returns 409 and nothing is saved; reload and retry. Publishing stores the previous and new published versions in the revision history and clears the draft.

The HTML body is sanitized on the server before storage: <script> tags, event handler attributes (onclick, …), javascript:/data: URIs, <iframe>/<embed>/<object>/<form>/<base> tags, and dangerous CSS constructs are stripped.

Success response (200) — for publish, the published template record (plus revision: 0 and the new documentVersion); for draft, the draft record (with its revision) and documentVersion:

{ "id": "cltpl123", "tenantId": "tnt_ScUtrVKUKGxtu7WY", "type": "verification", "locale": "en", "subject": "Verify your email — {{email}}", "htmlBody": "<!DOCTYPE html>...", "metadata": { "source": "code" }, "active": true, "createdAt": "2026-07-23T09:00:00.000Z", "updatedAt": "2026-07-23T09:00:00.000Z" }

Error responses

HTTPDescription
400Invalid template type or invalid locale
404Tenant or application not found
409A conflict-check token no longer matches (DRAFT_CONFLICT, PUBLISH_CONFLICT, DOCUMENT_CONFLICT)
413htmlBody exceeds the 500 KB limit, or metadata exceeds 256,000 characters
422Missing or invalid subject/htmlBody, invalid body or applicationId, metadata does not match the expected schema, or (publish) the pre-publish check failed; the response lists the issues

A published template takes effect immediately for all future emails of this type, locale, and scope. Save a draft and preview or test it before publishing.

Reset Template

DELETE/api/email-templates/{type}?locale={locale}Requires: manage:security

Reset one locale of the template in the selected scope: the published template and its draft are removed, and the previous published version is kept in the revision history. The locale query parameter is required.

After a reset, delivery follows the delivery order above (tenant template when inheritance is on, otherwise the built-in default).

Query parameterRequiredDescription
localeYesLocale to reset. Missing: 422
applicationIdNoApplication scope
expectedDocumentVersion, expectedRevision, expectedDraftId, expectedPublishedAtNoConflict-check tokens, as in PUT. A mismatch returns 409

Success response (200)

{ "success": true, "documentVersion": 3 }

Revision History

GET/api/email-templates/{type}/revisions?locale={locale}Requires: manage:security

Return the current draft, the 30 most recent revisions (id, subject, createdAt, active), and the documentVersion for one locale. Supports the applicationId query parameter.

Success response (200)

{ "draft": null, "revisions": [{ "id": "clrev123", "subject": "Sign in", "createdAt": "2026-10-08T09:00:00.000Z", "active": true }], "documentVersion": 2 }
POST/api/email-templates/{type}/revisionsRequires: manage:security

Restore a revision into the draft. Nothing is published until the draft is published with PUT.

Request body

{ "locale": "en", "revisionId": "clrev123", "applicationId": "app_123", "expectedRevision": 0, "expectedDraftId": null, "expectedDocumentVersion": 2 }

locale and revisionId are required; the conflict-check tokens are optional. Returns the draft record and documentVersion. Errors: 404 unknown revision or application, 409 conflict, 422 invalid request.

Applications

GET/api/email-templates/applicationsRequires: manage:security

List the tenant’s active applications with their email profile and inheritance setting.

Success response (200)

{ "applications": [{ "id": "app_123", "name": "Portal", "emailTheme": null, "emailTemplateInheritance": false }] }
PATCH/api/email-templates/applications/{applicationId}Requires: admin:all

Update an application’s email profile (theme) and template inheritance.

Request body (all fields optional; other fields are rejected)

{ "emailTemplateInheritance": true, "emailTheme": { "content": { "brandName": "Portal" } } }
FieldTypeDescription
emailTemplateInheritancebooleantrue: the application falls back to the tenant’s published templates before the built-in default. false (default for new applications): it does not
emailThemeobject | nullEmail profile used by the application’s built-in templates; null clears it. The theme is checked against every built-in template type before it is saved

Returns { "success": true }. Errors: 403 without admin:all, 404 unknown application, 413 body over 100,000 characters, 422 invalid profile.

Preview Template

POST/api/email-templates/{type}/previewRequires: manage:security

Render a subject and HTML body with realistic sample variables for the template type. Nothing is sent and nothing is stored.

Request body

{ "subject": "Verify your email — {{email}}", "htmlBody": "<!DOCTYPE html>..." }

Success response (200)

{ "subject": "Verify your email — [email protected]", "html": "<!DOCTYPE html>...", "variables": { "email": "[email protected]", "link": "https://console.auris.dev/verify-email?token=abc123", "expiresIn": "24 hours", "year": "2026", "month": "07", "day": "23", "date": "2026-07-23" } }

The variables field echoes the sample values that were substituted. The HTML body is sanitized before rendering; the subject is rendered as plain text (no HTML escaping of values).

Test Email

POST/api/email-templates/{type}/testRequires: manage:security

Render the given subject and HTML body with sample data and send them as a real email. By default the email goes to the authenticated administrator’s own address.

Request body

{ "subject": "Verify your email — {{email}}", "htmlBody": "<!DOCTYPE html>...", "recipientEmail": "[email protected]" }
FieldTypeRequiredDescription
subjectstringYesSubject line (with placeholders)
htmlBodystringYesHTML body (with placeholders)
applicationIdstringNoApplication scope, used for branding
recipientEmailstringNoOptional override recipient. When omitted (or empty), the test is sent to the authenticated admin’s own inbox. Must be a valid email address

Success response (200)

{ "success": true, "sentTo": "[email protected]" }

Error responses

HTTPDescription
400Invalid template type, invalid recipientEmail, or the caller’s email address could not be determined
422Missing or invalid subject/htmlBody, or the template fails the pre-publish check
500Email delivery failed

The rendered subject is prefixed with [TEST] so test emails are easy to distinguish from real transactional mail. Delivery uses the tenant’s SMTP configuration when present and active, otherwise the platform default sender.

Template Types

Auris supports thirteen transactional email template types:

TypeWhen SentVariables
verificationA new user registers and must verify their emailemail, link, expiresIn
password_resetA user requests a password resetemail, link, expiresIn
invitationA user is invited to join a tenantemail, orgName, role, inviterEmail, link, expiresIn
mfa_codeEmail-based two-factor authenticationemail, code, expiresIn
magic_linkPasswordless login via magic linkemail, link, approveLink, expiresIn, tenantName
login_alertA new login is detected on the accountemail, device, ipAddress, location, time
welcomeA user successfully verifies their emailemail, name, orgName, dashboardLink
password_changedA password change is confirmedemail, name, time, ipAddress
account_lockedAn account is locked after failed login attemptsemail, name, lockDuration, attempts, ipAddress, time
suspicious_loginAn unusual login is detectedemail, name, device, ipAddress, location, time, reason
email_changedThe primary email changes (sent to the old address)email, name, newEmail, time
license_issuedA license key is issuedkey, jwtToken, product, expiresAt, features
cibaSign-in approval requested via CIBA backchannel flowemail, appName, bindingMessage, approveUrl, denyUrl

The global date variables year, month, day, and date (format YYYY-MM-DD) are auto-injected into every render, in addition to the per-type variables above.

Template Syntax

  • {{variable}} — replaced with the value. In the HTML body, values are HTML-escaped automatically to prevent injection; in the subject line values are inserted as plain text.
  • {{{variable}}} — raw interpolation without escaping. Only for trusted, server-built HTML fragments.
  • {{#if variable}}...{{/if}} — the block is kept only when the variable resolves to a non-empty string; otherwise it is removed entirely (markup included). Example: the magic_link default template renders the secondary approve button only when approveLink is provided.

Unknown placeholders are left as-is in the output. Dot notation and loops are not supported.

<h1>Sign in to {{tenantName}}</h1> <p><a href="{{link}}">Sign in on this device</a></p> {{#if approveLink}} <p><a href="{{approveLink}}">Approve on the original device</a></p> {{/if}} <p>The link expires in {{expiresIn}}.</p>

Audit Events

Draft saves, publications, restores, resets, test sends, and application email profile changes are written to the tenant audit log with the acting user, tenant, application, template type, and locale. Template content is never recorded; test sends record only the recipient’s domain. See Webhooks for the event types (email_template.*, application.profile_updated, application.template_inheritance_changed).

Permissions Reference

PermissionDescription
manage:securityList, view, draft, publish, reset, restore, preview, and test email templates for the tenant and its applications; list applications
admin:allChange an application’s email profile and template inheritance