GET
/
api
/
marketing
/
templates
Email Templates
curl --request GET \
  --url https://onlyautomator.com/api/marketing/templates
{
  "success": true,
  "templates": [
    {
      "id": "welcome-template",
      "name": "Welcome Email",
      "description": "Sent to new users when they sign up",
      "thumbnail": "https://assets.onlyautomator.com/templates/welcome-thumb.png",
      "html_content": "<html><body><h1>Welcome, {{name}}!</h1><p>Thank you for joining OnlyAutomator...</p></body></html>",
      "created_at": "2023-01-15T10:30:45Z",
      "updated_at": "2023-03-22T14:15:30Z"
    }
  ]
}
This endpoint allows you to retrieve the list of available email templates and their details. Email templates are used for various communications with your users, including welcome emails, notifications, and marketing campaigns.

Authentication

This endpoint requires authentication with a valid user session.

Response

success
boolean
Indicates whether the request was successful
templates
array
List of available email templates

200 OK

{
  "success": true,
  "templates": [
    {
      "id": "welcome-template",
      "name": "Welcome Email",
      "description": "Sent to new users when they sign up",
      "thumbnail": "https://assets.onlyautomator.com/templates/welcome-thumb.png",
      "html_content": "<html><body><h1>Welcome, {{name}}!</h1><p>Thank you for joining OnlyAutomator...</p></body></html>",
      "created_at": "2023-01-15T10:30:45Z",
      "updated_at": "2023-03-22T14:15:30Z"
    },
    {
      "id": "password-reset",
      "name": "Password Reset",
      "description": "Sent when a user requests a password reset",
      "thumbnail": "https://assets.onlyautomator.com/templates/password-reset-thumb.png",
      "html_content": "<html><body><h1>Reset Your Password</h1><p>Click the link below to reset your password...</p></body></html>",
      "created_at": "2023-01-15T10:35:20Z",
      "updated_at": "2023-01-15T10:35:20Z"
    }
  ]
}

Create a New Template

To create a new email template, use a POST request to the same endpoint.
POST /api/marketing/templates

Request Body

name
string
required
Name of the template
description
string
required
Description of what the template is used for
html_content
string
required
HTML content of the template with variable placeholders
text_content
string
Optional text-only version of the template

Response

success
boolean
Indicates whether the template was created successfully
template
object
The newly created template with all properties

201 Created

{
  "success": true,
  "template": {
    "id": "new-template-123",
    "name": "Promotional Offer",
    "description": "Template for seasonal promotions and offers",
    "thumbnail": "https://assets.onlyautomator.com/templates/default-thumb.png",
    "html_content": "<html><body><h1>Special Offer For You!</h1><p>Hi {{name}}, we're offering a special discount...</p></body></html>",
    "created_at": "2023-04-18T09:12:33Z",
    "updated_at": "2023-04-18T09:12:33Z"
  }
}

Example Usage

// Fetch all templates
const getTemplates = async () => {
  const response = await fetch('https://onlyautomator.com/api/marketing/templates', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json'
    }
  });
  
  const data = await response.json();
  return data.templates;
};

// Create a new template
const createTemplate = async () => {
  const response = await fetch('https://onlyautomator.com/api/marketing/templates', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: 'Subscription Renewal',
      description: 'Template for subscription renewal reminders',
      html_content: `
        <html>
          <body>
            <h1>Subscription Renewal</h1>
            <p>Hello {{name}},</p>
            <p>Your subscription is due to renew on {{renewal_date}}...</p>
          </body>
        </html>
      `
    })
  });
  
  const data = await response.json();
  console.log('Created template:', data.template);
};

Variables

Email templates support dynamic variables that are replaced with actual values when the email is sent. Variables are enclosed in double curly braces: {{variable_name}}.

Common Variables

  • {{name}} - Recipient’s full name
  • {{first_name}} - Recipient’s first name
  • {{email}} - Recipient’s email address
  • {{company}} - Recipient’s company name
  • {{current_date}} - Today’s date

Response

200 - application/json

List of templates retrieved successfully

success
boolean
Example:

true

templates
object[]