Notifications API · templates
Render a template's source for a kind without keeping it
POST /email-templates/render
Render a template's source for a kind (a layout around previewKind's email) without keeping it — the editor's live preview, and how an agent checks a draft before saving it: answers the subject, the inbox preview, the html and its plain-text twin, rendered against data (as the kind's template data schema carries it) or the kind's sample.
422 TemplateInvalid with the stage, reason and line. A template is a TSX module in react-email's dialect: it exports subject (a string, or a function of the data), optionally preview, and the email as its default export — a function of the kind's template data returning react-email components (Html, Body, Container, Section, Row, Column, Heading, Text, Button, Link, Img, Hr, …) and plain HTML elements, imported from @manifold/email with the helpers money, date and plural (GET /email-templates/catalog answers the full declarations). It runs in a sandbox — no network, files, timers or other modules, 250 ms and 16 MB a render — and what it returns is held to the dialect: no script, event handler or class, links https:/http:/mailto:/tel:, images https:. Appends nothing: a render is a read of what the source would send, and the request row is acknowledged rather than committed. No idempotency key: a render records nothing, so a retry is simply another render.
Access
Requires settings:write or notifications:write.
Any one of these scopes is enough.
How scopes come from roles: Scopes and roles. Getting a token: Authentication and app tokens.
Retries
No idempotency key: a render records nothing, so a retry is simply another render.
Why every write carries a key: Idempotency and retries.
Facts appended
None. This call records nothing in a journal.
What a fact is: Facts and the journal.
AI agent tool
Agents call this as notifications_preview_email_template (Notifications: Preview an email template), in the notifications toolset.
Connecting an agent: AI agents.
Example
curl -X POST 'https://notifications.getmanifold.io/email-templates/render' \
-H "Authorization: Bearer $MANIFOLD_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"kind": "invoice",
"source": "import { Container, Heading, Text, money } from \"@manifold/email\";\nexport const subject = (data) => `Invoice ${data.invoice.number} from ${data.shop.name}`;\nexport default function Invoice(data) {\n return (\n <Container>\n <Heading>Thanks, {data.customer?.firstName ?? \"there\"}</Heading>\n <Text>{money(data.invoice.totals.totalCents, data.invoice.currency)} is due.</Text>\n </Container>\n );\n}\n"
}'const response = await fetch("https://notifications.getmanifold.io/email-templates/render", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.MANIFOLD_TOKEN}`, "Content-Type": "application/json" },
body: JSON.stringify({
"kind": "invoice",
"source": "import { Container, Heading, Text, money } from \"@manifold/email\";\nexport const subject = (data) => `Invoice ${data.invoice.number} from ${data.shop.name}`;\nexport default function Invoice(data) {\n return (\n <Container>\n <Heading>Thanks, {data.customer?.firstName ?? \"there\"}</Heading>\n <Text>{money(data.invoice.totals.totalCents, data.invoice.currency)} is due.</Text>\n </Container>\n );\n}\n"
}),
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
const answer = await response.json();{
"kind": "invoice",
"source": "import { Container, Heading, Text, money } from \"@manifold/email\";\nexport const subject = (data) => `Invoice ${data.invoice.number} from ${data.shop.name}`;\nexport default function Invoice(data) {\n return (\n <Container>\n <Heading>Thanks, {data.customer?.firstName ?? \"there\"}</Heading>\n <Text>{money(data.invoice.totals.totalCents, data.invoice.currency)} is due.</Text>\n </Container>\n );\n}\n"
}{
"subject": "Invoice INV-1042 from Ridgeline Outdoor",
"html": "<!DOCTYPE html …>",
"text": "THANKS, MAYA\n\n$618.30 is due.",
"durationMs": 41
}The panel writes this call in other languages. It does not send it: Manifold's APIs do not take calls from a web
page on another site, so run the call from your own code or terminal. The whole API as OpenAPI: notifications-manager.openapi.json. Base URL https://notifications.getmanifold.io.
Errors
Every refusal is a status and a JSON body whose _tag names it. A refused call changes nothing.
401
| Refusal | What it means | What to do |
|---|---|---|
Unauthorized reason | The token is missing, expired or not one Manifold issued. | Get a fresh token and send the call again. |
TokenAlreadyUsed tokenId | A single-use app token was already spent. | Mint a new token for this call. |
402
| Refusal | What it means | What to do |
|---|---|---|
SubscriptionRequired status | The organization's subscription has lapsed, so writes are refused. | An owner settles billing. Reads still work meanwhile. |
403
| Refusal | What it means | What to do |
|---|---|---|
TenantRequired userId | The token names no organization. | Choose the organization, then get a new token. |
ScopeRequired required | The token's roles do not grant the scope this call needs. | Ask an owner or admin for a role that grants it. |
409
| Refusal | What it means | What to do |
|---|---|---|
MirroredFromSource source | This area is fed by your source system until the organization goes live. | Make the change in the source system, or go live first. |
422
| Refusal | What it means | What to do |
|---|---|---|
TemplateInvalid stage, reason, line, column | With the stage, reason and line. | Fix the request. Sending it again unchanged gets the same answer. |
503
| Refusal | What it means | What to do |
|---|---|---|
RequestLogUnavailable tokenId, reason | The service could not record the request, so it did nothing. | Send the same request again shortly. |
How refusals work everywhere: Errors.
Used in
- Design your own emails, step 4: Preview a draft