Docs API Reference

POST /render

Render a template to HTML without sending it.

Overview

The /render endpoint hydrates a template with variables and returns the resulting HTML. Use this when you want to render emails but handle sending yourself.

Endpoint

POST /v1/render

Request Body

FieldTypeRequiredDescription
template_idstringYesThe ID of the template to render
variablesobjectNoKey-value pairs for variable substitution

Example Request

curl -X POST https://api.mailsh.it/v1/render \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tmpl_abc123",
    "variables": {
      "firstName": "Alice",
      "orderNumber": "12345",
      "trackingUrl": "https://example.com/track/12345"
    }
  }'

Response

Success (200)

{
  "html": "<!DOCTYPE html><html>...</html>",
  "subject": "Your order #12345 has shipped"
}
FieldTypeDescription
htmlstringThe fully rendered HTML email
subjectstringThe email subject (from template or variables)

Error (400)

{
  "error": "template_id is required"
}

Error (404)

{
  "error": "Template not found"
}

Variable Substitution

Variables in templates use the {{name|default}} syntax:

  • {{firstName}} - Required variable, no default
  • {{firstName|Friend}} - Uses “Friend” if not provided
  • {{company|}} - Empty string if not provided

When you call /render:

  1. Variables you provide replace the placeholders
  2. Variables you don’t provide use their inline defaults
  3. The final HTML contains no raw {{}} syntax

Code Examples

JavaScript

const response = await fetch('https://api.mailsh.it/v1/render', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.MAILSHIT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    template_id: 'tmpl_abc123',
    variables: {
      firstName: 'Alice',
    },
  }),
})

const { html, subject } = await response.json()

Python

import requests

response = requests.post(
    'https://api.mailsh.it/v1/render',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json',
    },
    json={
        'template_id': 'tmpl_abc123',
        'variables': {
            'firstName': 'Alice',
        },
    },
)

data = response.json()
html = data['html']
subject = data['subject']

Use Cases

  • Preview emails before sending
  • Store rendered HTML for later sending
  • Use your own sending infrastructure (SMTP, other providers)
  • Generate email content for testing