Using Templates

Templates let you create reusable email designs. Build a template once, then use it across multiple campaigns.

Create a template

curl -X POST https://api.cakemail.dev/templates \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Monthly Newsletter",
    "content": {
      "html": "<html><body><h1>{{title}}</h1><p>{{body}}</p></body></html>",
      "text": "{{title}}\n\n{{body}}"
    }
  }'

List templates

curl "https://api.cakemail.dev/templates?page=1&per_page=25" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Render a template

Preview how a template will look:

curl "https://api.cakemail.dev/templates/{template_id}/render" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Use a template in a campaign

When creating or updating a campaign, reference a template by ID instead of providing inline HTML:

curl -X PATCH https://api.cakemail.dev/campaigns/{campaign_id} \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content": {"template_id": 789}}'

Update a template

curl -X PATCH https://api.cakemail.dev/templates/{template_id} \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Newsletter",
    "content": {
      "html": "<html><body><h1>{{title}}</h1><p>{{body}}</p><footer>{{footer}}</footer></body></html>"
    }
  }'

Delete a template

curl -X DELETE https://api.cakemail.dev/templates/{template_id} \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Use a template with transactional emails

When sending a transactional email via the Email API, reference a template by ID and pass custom attributes to populate its merge tags:

curl -X POST https://api.cakemail.dev/v2/emails \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "recipient@example.com",
    "sender": {
      "name": "My App",
      "email": "noreply@myapp.com"
    },
    "content": {
      "subject": "Your Monthly Update",
      "template_id": 789
    },
    "custom_attributes": {
      "title": "April Newsletter",
      "body": "Here is your monthly update.",
      "footer": "© 2026 Your Company"
    }
  }'