Create Email Template API
 

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

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:

  1. Navigate to Settings > APIs > TRANSACTION PUSH/REPORT Settings.
  2. Click on the Click here to show API Secret to view the API Secret key.
  3. 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": [
"https://app-cdn.moengage.com/assets/LogoThumbnail.jpg"
]

Note:

  • Only URLs can be added as part of Email attachments.
  • A maximum of ten attachments are allowed.
  • The URL should start with https and end with a valid extension. The following extensions are not allowed: .dmg, .exe, .xls, .ddl, .class, .obj, .int, .gnt, .o, .so, .lbr, and .net

  • Individual attachments should be less than 6 MB, and the total size of the attachments should be less than 20 MB.
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 - This field contains the error code that provides a brief explanation of the error and is a String. For example, 400 - Bad Request, 401- Authentication required, and so on. This field is present in the response only in the case of errors.
  • message - This field describes why the request has failed and is a String. For example, in the case of a duplicate request (400- Bad Request), the following message will be present: 'Duplicate - template_id and template_version'.
  • details - This is a List of the error details objects. Each object contains the following information:

           { 

             "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>"

            }

  • request_id -  This field contains the unique id pertaining to the request.

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.

{
"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:<template_id> template_version:<template_version> is already present."
}
],
"request_id": "cLCcgLQj"
}

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

Sample cURL
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

200 400 401 415 429 5xx
Sample Response for a successful request
{
  "external_template_id": "d05a44f0-a7cf-471a-bcb6-63054800a367"
}

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.

    TemplateAPI_Dashboard.png
  • Can I create multiple templates with the same name?
    Yes, you can create multiple templates with the same name, provided they have different versions.
Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?