This API can be used to update an email template by specifying its external template id. You can specify whether the updated version of the template can be used in active campaigns in the request.
API Endpoint
PUT 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
The API request will be authenticated through Basic Authentication. Basic Authentication sends a Base64-encoded string containing your username and password with every API request. It encodes a 'username:password' string in Base64 and appends the encoded string with 'Basic '. This string is included in the authorization header as shown below:
{"Authorization":"Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U="}
The username and password details can be obtained from the MoEngage Dashboard. We've revamped the settings UI in the Dashboard. If you're using the API for the first time, follow these steps for the revamped and old UIs:
Revamped UI
- Navigate to Settings -> Account -> APIs.
- Click the Copy icon in the Campaign report/Business events/Custom templates tile in the API Keys section to copy the API Key.
- Use the App ID as the username and the Push API Key as the password to generate the authentication header.
Old UI
- Navigate to Settings -> APIs -> TRANSACTION PUSH/REPORT Settings.
- Click on the Click here to show APP Secret link to view the API SECRET.
- Use the APP ID as the username and the API SECRET as the password to generate the authentication header.
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 authentication parameter, used for access control, must be passed along with the request. To generate the authentication header, refer to Authentication. |
Request Body
Key | Required | Values | Description |
---|---|---|---|
external_template_id | Required | String | This field contains the unique identifier that is generated during the creation of the template. |
update_campaigns | Optional | Boolean |
This field contains a flag that is used to update all the campaigns that are currently using the template being updated to the newer version(that is being updated in this request). The default value for this flag is false. When the update_campaigns flag is true, all the campaigns running with this template will get updated to the latest version of the template, and when it is false, the new version of the template will be created, but there will be no change made to the template used in the existing campaigns. |
update_latest_version | Optional | Boolean |
If the value is "true", this API does not create a new version of the template but only updates its contents. |
basic_details | Required | JSON Object |
This field contains the basic details of the email template, such as the subject, email content, preview text, sender name, thumbnail URL, and attachments. For more information, refer to Basic Details. |
meta_info | Required | JOSN Object |
This field contains information about the template being created, such as the name of the template and the creator's details. Structure of meta_info: "meta_info": { "template_name": "<template name>", "template_version": "<template version>" The meta_info object contains the following fields:
All the fields in the meta_info are Strings. Note: The fields locale, variation, and group_id are non-editable. |
Response
Key | Data Type | Description |
---|---|---|
external_template_id | String | This field contains the unique template id corresponding to a successful template updation request. |
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 update a template using an invalid template-id, 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. |
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. |
Rate Limit
The rate limit is 100 RPM.
Sample cURL Request
curl --location --request PUT 'http://core.campaigns.api.moeinternal.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</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": "Test subject",
"attachments": [],
"thumbnail_url": "https://img.freepik.com/free-vector/bright-yellow-sunflower-design-decorations_1308-130330.jpg",
"sender_name": "Test sender",
"preview_text": "Sample preview text"
},
"meta_info": {
"template_name": "test_template",
"updated_by": "user1@moengage.com",
"template_version": "2.0"
},
"update_campaigns": false,
"external_template_id": "245952d4-4cdd-4d0d-9690-b3fae2dc9433"
}'
Sample Response
Sample Response for a successful request
{
"external_template_id": "eca024b7-a8ea-4f31-9154-5b80c85d18a9"
}
Sample Response for Invalid temnplate id
{
"error": {
"code": "400 Bad Request",
"message": "Invalid template id",
"details": [
{
"code": "MissingValue",
"target": "9925c8",
"message": "9925c8 is invalid template id."
}
],
"request_id": "BTkUaYgU"
}
}
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.