TagMangoTagMango Docs
Automation

Configure automation email

POST
/api/v1/external/automations/emails/templates

Configure the email that fires for a registered automation event. Supports three payload shapes:

  • Toggle{ event, active } enables/disables the automation. On a creator-global save (no mango) it cascades the flag to every per-mango row for the event.
  • Content save{ event, subject, template } (plus optional mango / active) writes template content. Omit mango to set the creator-global template; provide mango to set a per-mango override.
  • Per-mango override — any save containing mango auto-enables the creator-global row (so a per-mango override always has a backing enabled event). Callers do not need to pre-toggle the event separately.

Partial updates: subject, template, and active are all optional. Fields absent from the body are preserved on the stored record. At least one of active, template, or subject must be present.

Processing:

  1. HTML sanitization — <script>, <iframe>, event handlers (onclick/onerror/…), and javascript: URLs are rejected. Full HTML documents (<html>/<head>/<body> wrappers) are accepted; wrappers are stripped and any <head><style> blocks are preserved.
  2. Handlebars compile-test — template is compiled against the event's allowed variable catalogue; unknown variables are rejected.
  3. Unlayer design synthesis — a minimal visual-editor design is generated from the HTML so the template remains editable in the dashboard editor.
  4. Cascade writes — creator-global saves cascade active to per-mango rows; per-mango saves auto-enable the creator-global row.
AuthorizationBearer <token>

In: header

Header Parameters

x-whitelabel-host*string

Host name of the dashboard, ex: mydomain.tagmango.com

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://api-prod-new.tagmango.com/api/v1/external/automations/emails/templates" \  -H "x-whitelabel-host: string" \  -H "Content-Type: application/json" \  -d '{    "event": "mangoPurchase"  }'
{
  "_id": "69c77c57ad85cea56909a95e",
  "creator": "69945193ce0ecef7256a481f",
  "mango": "69bcc993473291fad8e4a7fa",
  "event": "mangoPurchase",
  "subject": "Your {{{mango}}} purchase is confirmed",
  "template": "<p>Hey {{{name}}}, thanks for buying <strong>{{{mango}}}</strong>!</p>",
  "active": true,
  "createdAt": "2026-04-23T11:17:44.000Z",
  "updatedAt": "2026-04-23T11:17:44.000Z"
}

{
  "code": 400,
  "type": "Bad Request",
  "statusMessage": "BAD_REQUEST",
  "errorCode": "AUTOMATION_TEMPLATE_TOO_LARGE",
  "message": "HTML templates are capped at 256 KB after UTF-8 encoding.",
  "result": "HTML templates are capped at 256 KB after UTF-8 encoding.",
  "success": false
}

{
  "code": 401,
  "type": "Unauthorized",
  "statusMessage": "UNAUTHORIZED",
  "message": "Invalid token",
  "success": false
}

{
  "code": 403,
  "type": "Forbidden",
  "statusMessage": "FORBIDDEN",
  "errorCode": "AUTOMATION_USER_NOT_CREATOR",
  "message": "The user has not completed creator onboarding or is not a valid creator account.",
  "result": "The user has not completed creator onboarding or is not a valid creator account.",
  "success": false
}

{
  "code": 404,
  "type": "Not Found",
  "statusMessage": "NOT_FOUND",
  "errorCode": "AUTOMATION_CREATOR_NOT_FOUND",
  "message": "The creator associated with the API key does not exist.",
  "result": "The creator associated with the API key does not exist.",
  "success": false
}