Get a Specific Email Template

The Get a Specific Email Template API fetches an email template using its template id.

API Endpoint

API Endpoint
GET  https://api-x.moengage.com/v2/email-templates/{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:

  1. Navigate to Settings > APIs > DATA API Settings.
  2. The User name is the DATA API ID, and the Password is the DATA API KEY. Copy these two values from the dashboard.
  3. 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 searched. The template id is a unique identifier that is generated at the time of template creation.

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 KEY 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.

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

        "template_id": "<Template id - the unique identifier that is created at the time of template creation>",

        "template_name": "<name of the template being fetched>",

        "subject": "<subject of the template being fetched>",

        "template_content": "<html content of the template>",

         "attachments":[List of attachments],

         "source":"<source of the template being fetched>",

        "editor": "Froala Editor",

        "created_date": "<timestamp of template creation>",

        "updated_at": "<timestamp of when the template was last updated>",

        "updated_by": "<details about who created or updated the template"

    }

  • The template_name (name field in the request), subject, template_content(html field in the request), source, and updated_by fields are the same as explained in the Request Body section of the Create Email Template API. For more information, refer to Create Email Template API.
  • The attachments field is a list of JSON Objects that contain the details about an attachment, such as its type, url, name, id, and so on. Example:

     "attachments": [

      {

          "id": "057ba4",

          "name": "https://appcdn.moengage.com/assets/",

          "type": "link",

           "fileType": "URL",

           "url": "https://appcdn.moengage.com/assets/LogoThumbnail.jpg"

         }

    ]

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:

  • code - This field contains the error code and is a String. Example: 400 (for a Bad Request), 401( for Authentication failures), and so on. This field is present in the response only in the case of errors.
  • title - This field contains the type of error encountered. Example: Bad Request, Authentication Required, and so on. This field is present in the response only in the case of errors.
  • description - This field describes why the request has failed and is a String. Example: 'MOE-APPKEY header is invalid or empty'.

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
curl --location --request GET 'https://api-x.moengage.com/v2/email-templates/<your_template_id>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic e3tEQVRBX0FQSV9JRH19Ont7REFUQV9BUElfS0VZfX0=' \
--header 'MOE-APPKEY: {DATA_API_ID}' \
--data-raw ''

Sample Response

200 400 401 429 5xx
Sample Response for a successful request
{
   "status": "success",
   "template_id": "645a0cec10e0307e6d7f7716",
   "template_name": "End_of_season_sale_template",
   "subject": "",
   "template_content": "<!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>",
   "attachments": [],
   "source": "Partner",
   "sender_name": "Your Brand Name",
   "editor": "Froala Editor",
   "created_date": "2023-05-09 09:05:46.350000",
   "updated_at": "2023-05-09 10:00:57.149000",
   "updated_by": "john.doe@example.com"
}

Postman Collections

We have made it easy for you to test the APIs. Click here to view it in Postman.

FAQ

  • What happens when you search for a deleted template?
    The error description contains the following message in such a case: “Template for given template id is archived”.
Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?