The Search Email Template API can be used to look up the email templates created in your MoEngage account.
API Endpoint
POST https://api-0X.moengage.com/v1.0/custom-templates/email/search
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 |
---|---|---|---|
page | Optional | Integer | This field contains the index of the pages to be returned in the search result. |
entries | Optional | Integer | This field contains the number of entries per page in the search result. |
template_name | Optional | String | This field indicates the name of the template. When this value is specified, the template that matches the name specified in this field will be returned. |
template_source | Optional | List of Strings | This field indicates the template source that created the template. For example: ["API", "MOENGAGE"]. When specified, the templates whose source matches that specified in this list will be returned. |
template_version | Optional | String | This field indicates the template version. When specified, the template whose template version matches that specified in this field will be returned. |
template_id | Optional | String | This field indicates the template id. When specified, the template whose template id matches that specified in this field will be returned. |
template_type | Optional | List of Strings |
This field indicates whether the template is a custom one or a pre-built one. Allowed values: CUSTOM, PRE_BUILT. When specified, the templates whose template type matches that specified in this list will be returned. |
created_by | Optional | List of Strings |
This field indicates the user who created the template. When specified, the templates for which the created_by user information matches that specified in this list will be returned. Example: ["user1@moengage.com", "user2@moengage.com"] |
updated_by | Optional | List of Strings |
This field indicates the user who updated the template. When specified, the templates for which the updated_by user information matches that specified in this list will be returned. Example: ["user1@moengage.com", "user2@moengage.com"] |
sort_params | Optional |
List of attributes and sort orders |
This field indicates the sorting parameters for the search result and the sort order. Example: "sort_params":[{"template_name": "ASCENDING","last_modified_date": "ASCENDING","last_modified_by": "ASCENDING"}] |
template_ids | Optional |
List of template ids |
This field indicates the list of the template ids and their versions that must be fetched. When this value is specified, the template that matches the id and version specified in this field will be returned. Structure: "external_template_ids": [ { "version": <version> ] Example: "template_ids":[{"external_template_id": "e1c95cb8-4f15-4f22-ae73-e9f47c9925c8", "version": 1}] |
group_id | Optional |
String |
This field indicates the group ID of the parent template. Pass the Group ID of the parent (default) template of the group to fetch all templates associated with that group. The "external_template_id" generated for the parent template acts as its group ID. |
is_grouped_response | Optional |
Boolean |
If the value is "true", this API fetches only the default template data, including additional fields such as unique locale count, unique variations, total templates in the group, and all individual templates that are not part of any group. If the value is "false", this API will fetch all individual templates and their template data. |
is_count_required | Optional |
Boolean |
If the value is "true", this API fetches total templates of the same request to support pagination on the UI. |
Note:
- You can send empty filters to fetch all the email templates.
- You can send only template_ids if you want specific older versions of the email template. In other cases, you will receive the latest version of the template.
- By default, the
is_default_template_of_group
flag is set to "true" for the default (parent) template and "false" for child templates.
Response
Key | Data Type | Description |
---|---|---|
data | Array of JSON Objects |
This field contains the list of email templates that satisfy the search criteria. "data": [ "meta_info": {<teamplate's meta info>}, "basic_details": {<template's email content>}, "created_by": "<created by user name>", } {...} ] For information about the template, refer to Basic Details and Meta Info. |
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 search for 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, 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. |
5xx |
Internal Server Error |
This response is returned when the system runs into an unexpected error. |
Rate Limit
The rate limit is 100 RPM.
Sample cURL Request
curl --location 'https://api-{{0X}}.moengage.com/v1.0/custom-templates/email/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic e3tBUFBfSUR9fTp7e0FQSV9TRUNSRVR9fQ==' \
--data-raw '{
"page": 1,
"entries": 10,
"template_name": "NAME_OF_THE_TEMPLATE(PARTIAL SEARCH)/ID_OF_TEMPLATE",
"template_source": ["API","MOENGAGE"],
"template_type": ["CUSTOM", "PRE_BUILT"],
"created_by": ["user1@moengage.com", "user2@moengage.com"],
"updated_by": ["user1@moengage.com", "user2@moengage.com"],
"sort_params": [{"template_name/last_modified_date/last_modified_by": "ASCENDING/DESCENDING"}],
"template_ids": [{"external_template_id": "ID_OF_TEMPLATE", "version": 1}]
}'
Sample Response
Sample Response for a successful request
{
"data": [
{
"external_template_id": "9b09875c-edda-42e9-8f9f-a7d0a9a2aa26",
"version": 2,
"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": "user1@moengage.com"
}
}
]
}
Sample Response for Invalid Field Value in Request
{
"error": {
"code": "400 Bad Request",
"message": "Invalid Field Value",
"details": [
{
"code": "InvalidValue",
"target": ["template_name", "created_by"],
"message": "Some of the field values are invalid"
}
],
"request_id": "eYXFWciv"
}
}
Sample Response for Authentication/Authorization failure
{
"error": {
"code": "401 Unauthorized",
"message": "Authentication required",
"details": [
{
"code": "InvalidValue",
"target": "APP_ID",
"message": "Invalid APP_ID is provided."
}
],
"request_id": "eYXFWciv"
}
}
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 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.