Beta Callout This is a Beta Feature. To enable it, please reach out to your CSM or mail us at support@moenage.com. |
The Create Email Template API can be used to create an email template in MoEngage. This API helps you upload templates created outside the MoEngage ecosystem to MoEngage and use them for campaign creation. The uploaded templates can be edited in the Froala editor (custom HTML editor) on the MoEngage Dashboard.
API Endpoint
POST https://api-0X.moengage.com/v1.0/custom-templates/email
Each customer is hosted on a different data center; you can find your data center number (value of X) by checking the data center and API endpoint mapping page.
Authentication
Basic authentication sends a Base64-encoded string containing a username and password for all API requests.
Do the following when you are using the API for the first-time authentication:
- Navigate to Settings > APIs > TRANSACTION PUSH/REPORT Settings.
- Click on the Click here to show API Secret to view the API Secret key.
- User name - APP ID and Password - API SECRET
For example, Basic Authentication encodes a 'username:password' using base64 encoding and prepends it with the string 'Basic '. The string is passed in the authorization header as follows:
{"Authorization":"Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U="}
Request Headers
Key | Required | Sample Values | Description |
---|---|---|---|
Content-Type |
Required |
{"Content-Type": "application/json"} |
Set the Content-Type header to application/json. |
Authorization |
Required |
{"Authorization": "Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U=="} |
This is the authentication parameter for access control and needs to be passed along with the request. The APP ID and API SECRET need to be picked up from the TRANSACTION PUSH API Settings in the MoEngage Dashboard, and a Basic Authorization header needs to be created and set in the header. Navigation: Settings -> API -> General Settings -> TRANSACTION PUSH/REPORT SETTINGS section. For more information, refer to Authentication. |
Request Body
Key | Required | Values | Description |
---|---|---|---|
basic_details
|
Required | JSON Object | This field contains the email content. This is where you define the email template being created. For more information, refer to Basic Details. |
meta_info | Required | JSON Object |
This field contains information about the template being created, such as the name, version, and ID of the template and the creator's details. For more information, refer to Meta Info. |
Basic Details
The basic_details JSON object contains the following information:
Key | Required | Values | Description |
---|---|---|---|
email_content | Required | String | This field contains the title of the message. |
subject | Required | String |
This field contains the subject of the email campaign. Example: "End of Season Sale!" |
attachments | Optional | Array of Strings |
This field contains the attachments to be included in the email. Example: "attachments": [ Note:
|
thumbnail_url
|
Required | String |
This field contains the image URL used to generate a preview in the Imported API Templates section on the MoEngage dashboard. |
sender_name | Required | String |
This field contains the name that is displayed in the inboxes of your recipients. Sender names are one of the first things people see when you send them an email. Example: "sender_name": "Your Brand Name" |
preview_text | Optional | String |
This field contains the preview text, the text that appears below the subject line in the inbox. Example: "preview_text": "Let Your Summer Look Shine" |
Meta Info
The meta_info JSON object contains the following information:
Key | Required | Values | Description |
---|---|---|---|
template_id | Required | String | This field contains the ID for the template and is unique. This ID should be generated by you and will be used for updating or retrieving the template using the template APIs. |
template_name | Required | String | This field contains the name of the template. This value should be generated by you and would be used for identifying the template. |
template_version | Required | String | This field contains the version of the template and is unique. This value should be generated by you and would be used for tracking the template's version. |
created_by | Required | String | This field contains details about who created the template. This value should be generated by you. For example, you can pass the email id of the user creating the template here. |
Response
Key | Data Type | Description |
---|---|---|
external_template_id | String | This field contains the unique template id corresponding to a successful template creation request and needs to be stored by you. This template id would be used for searching a specific template and updating it. |
error | JSON Object |
This field contains the reason for the request's failure. Structure: "error": { "code": "<error_code>", "message": "<error_message>" , "details": [], "request_id": "<unique identifier for the request> } The error object contains the following fields:
{ "code": "<Descriptive Error Code>", "target": "<Denotes the field causing the issue or a brief description of the error message in some cases >", "message": "<Descriptive Error Message>" }
For example, in the case of a 400 request where the request is trying to create a template that is already present, the following error object is returned. { |
Response Codes
Status Code | Request State | Description |
---|---|---|
200 |
Success |
This response is returned when the request is processed successfully. |
400 |
Bad Request |
This response is returned when the required parameters are missing from the request, or when the provided parameters are invalid, or when a template already exists with the same version, name, or id. |
401 |
Authorization Failure |
This response is returned when the authorization parameters are missing in the HTTP Auth Header. |
415 |
Unsupported File Type |
This response is returned when the header Content-Type is not provided/is not supported. |
429 |
Rate Limit Breach |
This response is returned when the number of requests per minute has exceeded the rate limit, or the number of templates has exceeded the allowed quota per channel. |
5xx |
Internal Server Error |
This response is returned when the system runs into an unexpected error. |
Rate Limit
The rate limit is 100 RPM. You can upload a maximum of 100 templates per channel.
Sample cURL Request
curl --location 'https://api-0X.moengage.com/v1.0/custom-templates/email' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U==' \
--data-raw '{
"basic_details": {
"email_content": "<!DOCTYPE html><html><head><title>Sample Webpage</title></head><body><h1>Welcome to My Sample Webpage 1</h1><p>This is a small example of an HTML webpage.</p><p>Below is an unordered list:</p><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul><p>Here'\''s an image:</p><img src=\"https://example.com/sample-image.jpg\" alt=\"Sample Image\"><p>Visit our <a href=\"https://www.example.com\">website</a> for more information.</p></body></html>",
"subject": "Hi, Test subject 1",
"attachments": [],
"thumbnail_url": "https://img.freepik.com/free-vector/bright-yellow-sunflower-design-decorations_1308-130330.jpg",
"sender_name": "test sender 1"
},
"meta_info": {
"template_id": "0192837",
"template_name": "test_template_1",
"template_version": "0",
"created_by": "john.doe@example.com"
}
}'
Sample Response
Sample Response for a successful request
{
"external_template_id": "d05a44f0-a7cf-471a-bcb6-63054800a367"
}
Sample Response for validation failure due to invalid request data
{
"error": {
"code": "400 Bad Request",
"message": "Validation failed because of invalid request data",
"details": [
{
"code": "MissingValue",
"target": "template_id",
"message": "template_id value is too short"
}
],
"request_id": "LMwPhRMB"
}
}
Sample Response for when the Request Body is empty
{
"code": "400 Bad Request",
"target": "template_name",
"message": "request_body is missing."
}
Sample Response for when the Template Name is empty in the Request
{
"error": {
"code": "400 Bad Request",
"message": "Validation failed because of invalid request data",
"details": [
{
"code": "MissingValue",
"target": "template_name",
"message": "template_name value is required but value is passed empty."
}
],
"request_id": "jUxStmFn"
}
}
Sample Response for Invalida Data Types in the Request Fields
{
"error": {
"code": "400 Bad Request",
"message": "Validation failed because of invalid request data",
"details": [
{
"code": "InvalidValue",
"target": "email_content",
"message": "email content is invalid."
}
],
"request_id": "REQCNzcE"
}
}
Sample Response for Missing Mandatory Fields in the Request
{
"error": {
"code": "400 Bad Request",
"message": "Validation failed because of invalid request data",
"details": [
{
"code": "MissingValue",
"target": "template_name",
"message": "template_name value is required but value is passed empty."
}
],
"request_id": "eYXFWciv"
}
}
Sample Response for Invalid Extensions in Attachments in the Request
{
"error": {
"code": "400 Bad Request",
"message": "Validation failed because of invalid request data",
"details": [
{
"code": "InvalidValue",
"target": "attachments",
"message": "Email attachments should have valid extensions"
}
],
"request_id": "eYXFWciv"
}
}
Sample Response for When Individual Attachments Exceed the Allowed Limits in the Request
{
"error": {
"code": "400 Bad Request",
"message": "Validation failed because of invalid request data",
"details": [
{
"code": "InvalidValue",
"target": "attachments",
"message": "Email attachments should be valid one with size less than 6 MB."
}
],
"request_id": "eYXFWciv"
}
}
Sample Response for Duplicate Request
{
"error": {
"code": "400 Bad Request",
"message": "Duplicate - template_id and template_version",
"details": [
{
"code": "InvalidValue",
"target": "Duplicate - template_id and template_version",
"message": "template_id:EndOfSeasonSale template_version:10 is already present."
}
],
"request_id": "cLCcgLQj"
}
Sample Response for Template Limit Breach
{
"error": {
"code": "400 Bad Request",
"message": "Maximum Template limit exceeded",
"details": [
{
"code": "NotSupported",
"target": "Maximum Template limit exceeded",
"message": "You have already created maximum allowed template allowed for client"
}
],
"request_id": "eLeZXIlW"
}
}
Sample Response for Authentication/Authorization failure
{
"title": "Authentication required",
"description": "MOE-APPKEY missing in Authentication Header"
}
Sample Response for Unsupported Media Type
{
"title": "Unsupported media type",
"description": "Content type is not supported"
}
Sample Response for Rate Limit Breach
{
"response_id": "OUUkHvcn",
"type": "custom_template",
"error": {
"code": "Too Many Requests",
"message": "API rate limit breached. Current limit: n/m mins"
}
}
Sample Response for Template Limit Breach
{
"error": {
"code": "400 Bad Request",
"message": "Maximum Template limit exceeded",
"details": [
{
"code": "NotSupported",
"target": "Maximum Template limit exceeded",
"message": "You have already created maximum allowed template allowed for client"
}
],
"request_id": "eLeZXIlW"
}
}
Sample Response for server side errors
{
"title": "Internal Server Error",
"message": "An unexpected error was encountered while processing this request. Please contact MoEngage Team"
}
Postman Collections
We have made it easy for you to test the APIs. Click here to view it in Postman.
FAQs
-
How do I access templates created using this API on the MoEngage Dashboard?
You can access templates created using the Create Email Template API in the Imported API Templates tab in the second step of campaign creation in the MoEngage Dashboard, as illustrated in the image below.
-
Can I create multiple templates with the same name?
Yes, you can create multiple templates with the same name, provided they have different versions.