POST
/
api
/
marketing
/
test-template
Test Template
curl --request POST \
  --url https://onlyautomator.com/api/marketing/test-template \
  --header 'Content-Type: application/json' \
  --data '{
  "template_id": "welcome-template",
  "to_email": "test@example.com",
  "subject": "Welcome to OnlyAutomator! (TEST)",
  "test_data": {
    "name": "John Doe",
    "subscription_level": "Premium",
    "account_created": "2023-04-01"
  }
}'
{
  "success": true,
  "message": "Test email sent successfully",
  "email_id": "email_01H2XYZABCDEF123456789012"
}
This endpoint allows you to test an email template by sending a test email to a specified email address with sample data. This is useful for previewing how your templates will render before using them in actual campaigns.

Authentication

This endpoint requires authentication with a valid user session.

Request Body

template_id
string
required
The ID of the template to test
to_email
string
required
The email address to send the test email to
subject
string
required
Subject line for the test email
test_data
object
Sample data to populate template variables

Response

success
boolean
Indicates whether the test email was sent successfully
message
string
Status message about the test
email_id
string
Unique identifier for the sent email

200 OK

{
  "success": true,
  "message": "Test email sent successfully",
  "email_id": "email_01H2XYZABCDEF123456789012"
}

400 Bad Request

{
  "success": false,
  "message": "Missing required fields",
  "errors": [
    "template_id is required",
    "to_email is required"
  ]
}

404 Not Found

{
  "success": false,
  "message": "Template not found",
  "error": "No template exists with ID 'non-existent-template'"
}

Example Usage

Here’s how you can test a welcome email template:
// Example: Testing a welcome email template
const response = await fetch('https://onlyautomator.com/api/marketing/test-template', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    template_id: 'welcome-template',
    to_email: 'test@example.com',
    subject: 'Welcome to OnlyAutomator! (TEST)',
    test_data: {
      name: 'John Doe',
      subscription_level: 'Premium',
      account_created: '2023-04-01'
    }
  })
});

const data = await response.json();
console.log(data);

Body

application/json
template_id
string
required

The ID of the template to test

Example:

"welcome-template"

to_email
string
required

The email address to send the test email to

Example:

"test@example.com"

subject
string
required

Subject line for the test email

Example:

"Welcome to OnlyAutomator! (TEST)"

test_data
object

Sample data to populate template variables

Example:
{
"name": "John Doe",
"subscription_level": "Premium",
"account_created": "2023-04-01"
}

Response

Test email sent successfully

success
boolean
Example:

true

message
string
Example:

"Test email sent successfully"

email_id
string
Example:

"email_01H2XYZABCDEF123456789012"