The Update a Specific Email Template API can be used to update an email template by specifying its template id. The template id is a unique identifier that is generated by MoEngage during template creation.
API Endpoint
PUT https://api-x.moengage.com/v2/email-templates/{template_id}
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 > DATA API Settings.
- The User name is the DATA API ID, and the Password is the DATA API KEY. Copy these two values from the dashboard.
- 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="}
Generate the authorization header using the DATA API ID and DATA API KEY in the format shown above.
Path Parameter
Key | Required | Value | Description |
---|---|---|---|
id |
Required |
String |
This is the Template id of the template being updated. The template id is a unique identifier that is generated at the time of template creation using the Create Email Template API. Example: {"id": "63f30792c66ddcaac2ef9109"} |
Request Headers
Key | Required | Sample Values | Description |
---|---|---|---|
MOE-APPKEY |
Required |
{"MOE-APPKEY": "APP ID"} |
This is the APP ID of your MoEngage account. The MOE-APPKEY has to be passed along with the request. You can find your MoEngage APP ID in the MoEngage Dashboard API Settings. Navigation: Settings -> API -> General Settings -> DATA API section. For more information, refer to Authentication. Note: You can also fetch the APP ID from the following navigation: Settings -> App -> General Settings. |
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 DATA API ID and DATA API KEY need to be picked up from the DATA API Settings in MoEngage Dashboard, and a Basic Authorization header needs to be created and set in the header. Navigation: Settings -> API -> General Settings -> DATA API section. For more information, refer to Authentication. |
Request Body
Key | Required | Values | Description |
---|---|---|---|
name | Required | String |
This field contains the updated name of the template. Example: "End_Of_Season_Sale_Template". Note:
|
html | Required | JSON Object |
This field contains the updated message body of the email. The HTML tag and BODY tag (with text/tags) are mandatory. The SCRIPT tag is not allowed. Example: "html": "<!DOCTYPE html> \n\n body table td, \n\n \t\t\t |
subject | Optional | String |
This field contains the updated subject of the email campaign. Example: "End of Season Sale!" |
attachments | Optional | List of JSON Objects |
This field contains the updated attachments. Example: "attachments": [ Note:
|
sender_name | Optional | String |
This field contains the updated sender name (the sender name is 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" |
source | Required | String |
This field contains updated information about the source of template creation. This can be the name of the email partner. Example: "source": "Partner" |
updated_by | Optional | String |
This field contains information about who updated the template. Example: "updated_by": "test_partner" "updated_by": "john.doe@example.com" Note: Only alphanumerics, spaces, and hyphens are allowed in this field. This field can also contain the email ID of the person updating the template. The email id should be in the right format and a valid one. |
Response
Key | Data Type | Description |
---|---|---|
status | String | This field contains the status of the request and denotes whether it was successful or not. Example: "status": "success", "status": "error" |
data | JSON Object |
This field contains the id of the created template when the request is successful and the error details in case of an unsuccessful request. Successful Request The data object contains the following fields in the case of a successful request: Structure: "data": { "id": "<template_id>", "msg": "<success_message>" }
Unsuccessful Request The data object contains the following fields in the case of errors: Structure: "data": { "code": "<error_code>", "title": "<type of error>", "description": "<error_message>" } The error object contains the following fields:
|
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. |
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 limits are at the app level, and a maximum of thousand (sum of all the API requests per app)requests are allowed for an app per minute.
Sample cURL Request
curl --location --request PUT 'https://api-x.moengage.com/v2/email-templates/{{template_id}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic e3tEQVRBX0FQSV9JRH19Ont7REFUQV9BUElfS0VZfX0=' \
--header 'MOE-APPKEY: {DATA_API_ID}' \
--data '{
"name": "End_Of_Season_Sale_Template",
"html": "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title></title><style>\n \n body table{\n border-collapse: collapse;\n }\n\n body table td, body table th{\n border: 1px solid rgb(0, 0, 0);\n }\n\n \t\t\t</style></head><body aria-disabled=\"false\"><p>Your Updated Email Content</p></body></html>",
"subject": "End of season sale!",
"attachments": [
"https://app-cdn.moengage.com/asstes/LogoThumbnail.jpg"
],
"sender_name": "Your Brand Name",
"source": "Partner",
"updated_by": "john.doe@example.com"
}'
Sample Response
Sample Response for a successful request
{
"status": "success",
"data": {
"id": "63f4962d4d31f4c68d980a01",
"msg": "Custom email template updated"
}
}
Sample Response for validation failure due to invalid request data
{
"status": "error",
"data": {
"code": 400,
"title": "Invalid request body",
"description": "MOE-APPKEY header is invalid or empty"
}
}
Sample Response for when the name field (template name)is empty in the request
{
"status": "error",
"data": {
"code": 400,
"title": "Invalid email name",
"description": "Name field is empty"
}
}
Sample Response for when the html field is empty in the request
{
"status": "error",
"data": {
"code": 400,
"title": "Invalid email body",
"description": "Email body should not be empty"
}
}
Sample Response for when an invalid template id is passed in the request
{
"status": "error",
"data": {
"code": 400,
"title": "Invalid template id",
"description": "Please provide a valid template id"
}
}
Sample Response for Authentication/Authorization failure
{
"status": "error",
"data": {
"code": 401,
"title": "Authentication required",
"description": "Invalid APP_ID used in Authentication Header"
}
}
Sample Response for Rate Limit Breach
{
"status": "error",
"data": {
"code": 429,
"title": "rate limiter exception",
"description": "Exceeded rate limit for this app"
}
}
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
-
If I pass don't pass a few fields in the request and the created template has them already, will they be retained post the update?
The update request will overwrite the existing template with the template shared in the update request. If the update request does not have some of the fields that the created template had, the updated template will not have them too. For example, if you do not pass any attachments in the update request, the updated template will not have any attachments, even if it had attachments while it was created.