Update In-app Template API

This API allows you to update an In-app template as per your requirements.

API Endpoint

API Endpoint
PUT https://api-0X.moengage.com/v1.0/custom-templates/inapp/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="}

Follow the steps below to obtain the username and password details from the MoEngage Dashboard:

API authentication.png

  1. Navigate to Settings > Account > APIs.
  2. Copy the following details:
    • Username: Under Workspace ID (earlier App ID), click the copy icon to copy the username.
    • Password: In the API keys section, click the copy icon in the Campaign report/Business events/Custom templates/Catalog API tile to copy the API key.
  3. Use the above details to authenticate the API requests.

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 in the request. To generate the authentication header, refer to Authentication.

Request Body

Key Data Type Required Description
external_template_id String Mandatory

The external template ID needs to be updated. This field contains the unique identifier that is generated during the creation of the template.

Example:

4a1afbc5-4c31-4f19-8c23-793e27af01aa

update_campaigns Boolean Optional
(default value: false)

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.

basic_details JSON Mandatory

Details about the template, including its payload and template type.

  • payload:
    • Stringify json/text/html. The data type will be a string.
    • No limit restriction on field length
  • inapp_template_type:
    • string value, two options possible - SELF_HANDLED or INAPP_HTML

Example:

{
"payload": "MESSAGE",
"inapp_template_type": "INAPP_HTML"
}

 

meta_info JSON Mandatory

This field will update template information, such as the name of the template and the update's details.

Keys:

  • template_name
  • updated_by

The version of the templates will be increased by 1 after every template update.

Example:

{
  "template_name": "test",
  "updated_by": "test@ABC.com"
}

Response

Status Key Data Type Description
Success external_template_id String

This field contains the unique ID corresponding to a successful custom template update. This template ID is used as header input for updates, searches, or any kind of template modifications in a later stage.

Failure 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 the sample error response, refer here.

Response Codes

Status Code Request State Description

200

Success

Template updated successfully.

400

Bad Request

This response is returned when the required parameters are missing from the request, when the provided parameters are invalid, or when a template already exists with the same version, name, or ID.

5xx

Internal Server Error

This response is returned when the system runs into an unexpected error.

Sample cURL Request

cURL
curl --location --request PUT 'https://api-0X.moengage.com/v1.0/custom-templates/inapp' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic Q000RDFMWk4ySU1KTkJZOVVMWEFVNzNEOlIxWk1PS0FYUENCNg==' \
--data-raw '{
"external_template_id": "4e92fb87-9c58-43b4-ae03-f2e281d23077",
"update_campaigns": false,
"basic_details": {
"payload": "<html>\n <head>\n \n <title>HTML Gamification Tempalates - Scratch Card</title>\n \n</head>\n<body>\n\n <div class=\"screen-1\">\n <h2>Scratch And Win</h2>\n <h4>Exciting Prized Await You!</h4>\n <div class=\"card-container\">\n <div id=\"card\" class=\"scratchpad\"></div>\n </div>\n </div>\n \n <div class=\"winning-screen\">\n <div class=\"greeting-text\">\n <p>Congratulations, you won <span></span></p>\n </div>\n <div class=\"greeting-img\">\n <div class=\"card-container\" id=\"target\">\n <div class=\"scratchpad\">\n\n </div>\n </div>\n <div>\n <p>Copy this code and use during checkout.</p>\n <button onclick=\"moengage.openRichLanding('\''https://www.moengage.com'\''); moengage.trackClick(1); moengage.dismissMessage();\">Continue shopping</button>\n </div>\n </div>\n </div>\n \n <div class=\"loosing-screen\">\n <div class=\"greeting-text\">\n\n <p>Sorry, You didn'\''t win anything</p>\n </div>\n <div class=\"greeting-img\">\n <div class=\"card-container\">\n <div class=\"scratchpad\">\n <p>Better luck next time</p>\n </div>\n </div>\n <button onclick=\"moengage.openRichLanding('\''https://www.moengage.com'\''); moengage.trackClick(1); moengage.dismissMessage()\">Continue shopping</button>\n </div>\n </div>\n</body>\n</html>",
"inapp_template_type": "INAPP_HTML"
},
"meta_info": {
"template_name": "test template - updated",
"updated_by": "chinmay1@moengage.com"
}
}'

Sample Response

200 400
{
"external_template_id": "4a1afbc5-4c31-4f19-8c23-793e27af01aa"
}

Previous

Next

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?