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
The ID of the template to test
The email address to send the test email to
Subject line for the test email
Sample data to populate template variables
Response
Indicates whether the test email was sent successfully
Status message about the test
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: '[email protected]',
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);
The ID of the template to test
The email address to send the test email to
Subject line for the test email
Example:"Welcome to OnlyAutomator! (TEST)"
Sample data to populate template variables
Example:{
"name": "John Doe",
"subscription_level": "Premium",
"account_created": "2023-04-01"
}
Test email sent successfully
Example:"Test email sent successfully"
Example:"email_01H2XYZABCDEF123456789012"