Skip to content

Templates API

Create, edit, validate, preview, and publish project email templates through the server-side Integration API at /integration/v1/email/templates. Keep the token on your backend.

Node.js

ts
import { createEmailsClient } from '@funnelsgrove/emails';

const emails = createEmailsClient({
  privateToken: process.env.FUNNELSGROVE_PRIVATE_TOKEN!,
});

const template = await emails.createTemplate({
  slug: 'order-confirmation',
  name: 'Order confirmation',
  draft: {
    subject: 'Order {{ORDER_ID}}',
    previewText: 'Your order is confirmed.',
    html: '<p>Order {{ORDER_ID}}</p><p>Total: {{PRICE}}</p>',
    text: 'Order {{ORDER_ID}}\nTotal: {{PRICE}}',
    variables: {
      ORDER_ID: 'string',
      PRICE: 'number',
    },
  },
});

await emails.updateTemplate(template.id, {
  draft: { subject: 'Order {{ORDER_ID}} confirmed' },
});

await emails.validateTemplate(template.id);
await emails.publishTemplate(template.id);

Project CLI

bash
fgrove email pull --workspace "$WORKSPACE" --project "$PROJECT"
# Edit emails/templates/order-confirmation/ locally.
fgrove email validate
fgrove email push --workspace "$WORKSPACE" --project "$PROJECT"
fgrove email template publish order-confirmation --workspace "$WORKSPACE" --project "$PROJECT"

Templates must pass validation before publishing. Sending uses the published version by slug.