You can use the Personalized Preview API to preview the personalized content for a specific user in MoEngage. This API can retrieve the Personalized message content.
API Endpoint
POST https://api-0X.moengage.com/core-services/v1/personalization/preview
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="}
You can obtain the username and password details from the MoEngage Dashboard.
- Navigate to Settings -> Account -> APIs.
- 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 tile to copy the API key.
- Use these 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. |
MOE-APPKEY | Required |
{“MOE-APPKEY”: “Workspace ID”} |
This is the workspace ID (earlier APP ID) of your MoEngage workspace. The MOE-APPKEY has to be passed in the request. You can find your MoEngage Workspace ID in the MoEngage Dashboard:
Settings -> Account -> APIs -> Workspace ID (earlier app id) For more information, refer to Authentication. |
Data-compression | Optional |
|
This parameter is used to pass the payload in compressed format. |
Request Body
Key | Required | Values | Description |
---|---|---|---|
request_id | Required | String | This field denotes the request ID for which the personalized preview is accessed. |
personalization_content | Required | JSON Object | This object contains the personalization content details. For more information, refer to Personalization Content. |
user_details | Optional | JSON Object | This object contains the user details. For more information, refer to User Details. |
personalization_details | Required | JSON Object | This object contains the personalization details. For more information, refer to Personalization Details. |
Personalization Content
Key | Required | Values | Description |
---|---|---|---|
payload | Optional | JSON Object | This field denotes the data being transferred within the API request or response. The field values can contain any name and number of keys, providing flexibility to include all necessary information such as user data, event details, or other parameters required for processing. |
Custom template data | Optional | JSON Object | This object contains the custom template details. For more information, refer to Custom Template Data. |
info |
Information Either payload or custom template data object should have a value. |
User Details
Key | Required | Values | Description |
---|---|---|---|
identifier | Required | string | This field denotes the unique key used to specify a particular user or entity. This could be an ID, email, or phone number that uniquely identifies the user within the system. |
identifier_value | Required | string | This field denotes the corresponding value of the selected identifier. It represents the specific user or entity being targeted. For example, if the identifier is "email," the identifier value could be "user@example.com". |
info |
Information If you are using user details in request_body, then identifier and identifier_value field values are mandatory. |
Personalization Details
Key | Required | Values | Description |
---|---|---|---|
event_name | Optional | string | This field denotes the event name for which the personalization details of the personalization preview is accessed. This is required if an event attribute is present in the payload. |
channel | Required | string | This field denotes the channel for which the personalization details of the personalization preview is accessed. |
user_attributes | Optional | JSON Object | This field denotes key-value pairs that represent specific user characteristics or properties. The field values can contain any name and number of keys, allowing you to include various user-specific details. |
event_attributes | Optional | JSON Object | This field denotes the key-value pairs that describe the properties of a particular event. The field values can contain any name and number of keys, enabling you to include details like event type, time, or associated metadata. |
info |
Information
|
Custom Template Data
Key | Required | Values | Description |
---|---|---|---|
template_id | Required | string | This field denotes the template ID for which the custom template data for personalization preview is accessed. |
version | Required | string | This field denotes the version for which the custom template data for personalization preview is accessed. |
info |
Information If you are using custom template data in personalization_content, then template ID and version field values are mandatory. |
Rate Limit
You can create 10000 requests per minute.
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, when the provided parameters are invalid, or when the custom template ID and version don't exist in the dashboard . |
401 |
Unauthorized |
The request does not have valid authentication credentials. |
429 |
Too Many Requests |
Too Many requests, there won't be any response body for this. |
500 |
Internal Server Error |
This response is returned when the system runs into an unexpected error. |
Sample cURL Request
curl --location 'https://api-0X.moengage.com/core-services/v1/personalization/preview' \
--header 'content-type: application/json' \
--header 'MOE-APPKEY: {{Workspace_ID or APP_ID}}' \
--header 'Authorization: Basic {{Authorization_Key}}' \
--data '{
"request_id": "2",
"personalization_details": {
"event_name": "MOE_USER_PROFILE_UPDATED",
"channel": "EMAIL",
"user_attributes": {
"Gender": "Female"
}
},
"personalization_content": {
"payload": {
"user_attribute_personalization": "<!DOCTYPE html>\n<html>\n<head>\n<title>User Profile Update Example</title>\n</head>\n<body>\n<p>Hi {{UserAttribute['\''First Name'\'']}},\n Your profile has been updated successfully.\n</p>\n<p>Here are your updated details:\n First Name: {{UserAttribute['\''First Name'\'']}}\n Last Name: {{UserAttribute['\''Last Name'\'']}}\n Email: {{UserAttribute['\''Email'\'']}}\n Mobile: {{UserAttribute['\''Mobile Number (Standard)'\'']}}\n Gender: {{UserAttribute['\''Gender'\'']}}\n</p>\n</body>\n</html>"
}
},
"user_details": {
"identifier": "ID",
"identifier_value": "JOHN012"
}
}'
curl --location 'https://api-0X.moengage.com/core-services/v1/personalization/preview' \
--header 'content-type: application/json' \
--header 'MOE-APPKEY: {{Workspace_ID or APP_ID}}' \
--header 'Authorization: Basic {{Authorization_Key}}' \
--data '{
"request_id": "2",
"personalization_details": {
"event_name": "App_Opened",
"channel": "EMAIL",
"user_attributes": {
"Gender": "Female"
},
"event_attributes": {
"App_Version": "1.0.2"
}
},
"personalization_content": {
"payload": {
"event_attribute_personalisation": "<!DOCTYPE html>\n<html>\n<head>\n<title>User Profile Update Example</title>\n</head>\n<body>\n<p>Hi {{UserAttribute['\''First Name'\'']}},\n Your profile has been updated successfully.\n</p>\n<p>Here are your updated details:\n event_attribute_1: {{EventAttribute['\''Alert Channel'\'']}}\n App_Version: {{EventAttribute['\''App_Version'\'']}}\n Email: {{UserAttribute['\''Email'\'']}}\n Mobile: {{UserAttribute['\''Mobile Number (Standard)'\'']}}\n Gender: {{UserAttribute['\''Gender'\'']}}\n</p>\n</body>\n</html>"
}
},
"user_details": {
"identifier": "ID",
"identifier_value": "JOHN012"
}
}'
curl --location 'https://api-0X.moengage.com/core-services/v1/personalization/preview' \
--header 'content-type: application/json' \
--header 'MOE-APPKEY: {{Workspace_ID or APP_ID}}' \
--header 'Authorization: Basic {{Authorization_Key}}' \
--data '{
"request_id": "12345",
"personalization_details": {
"event_name": "App_Opened",
"channel": "PUSH",
"user_attributes":{
"First Name": "John"
},
"event_attributes":{
"App Version": "34232"
}
},
"personalization_content": {
"custom_template_data": {
"template_id": "5b7d04c6-8ddc-4957-80d9-c67266079609",
"version": "1"
}
},
"user_details": {
"identifier": "ID",
"identifier_value": "JOHN012"
}
}'
curl --location 'https://api-0X.moengage.com/core-services/v1/personalization/preview' \
--header 'content-type: application/json' \
--header 'MOE-APPKEY: {{Workspace_ID or APP_ID}}' \
--header 'Authorization: Basic {{Authorization_Key}}' \
--data '{
"request_id": "12345",
"personalization_details": {
"event_name": "App_Opened",
"channel": "SMS",
"user_attributes": {
"First Name": "John Doe"
},
"event_attributes": {
"App Version": "125104"
}
},
"personalization_content": {
"payload": {
"Content Block" : "{{ContentBlock['\''simple_text_cb'\'']}}"
}
},
"user_details": {
"identifier": "ID",
"identifier_value": "JOHN012"
}
}'
curl --location 'https://api-0X.moengage.com/core-services/v1/personalization/preview' \
--header 'content-type: application/json' \
--header 'MOE-APPKEY: {{Workspace_ID or APP_ID}}' \
--header 'Authorization: Basic {{Authorization_Key}}' \
--data '{
"request_id": "12345",
"personalization_details": {
"channel": "SMS",
"user_attributes": {
"First Name": "John Doe"
}
},
"personalization_content": {
"payload": {
"Content Api" : "{% set var=ContentApi.testing_content_api({({\"params\":{\"q\":\"London,uk\",\"appid\":\"{{Workspace_ID or APP_ID}}\"},\"static_params\":{},\"dynamic_params\":{},\"request_body\":{}})})%}{{var.name}}"
}
},
"user_details": {
"identifier": "ID",
"identifier_value": "JOHN012"
}
}'
curl --location 'https://api-0X.moengage.com/core-services/v1/personalization/preview' \
--header 'content-type: application/json' \
--header 'MOE-APPKEY: {{Workspace_ID or APP_ID}}' \
--header 'Authorization: Basic {{Authorization_Key}}' \
--data '{
"request_id": "12345",
"personalization_details": {
"channel": "SMS"
},
"personalization_content": {
"payload": {
"product_set" : "{% if ProductSet.test_prod%}{% for product in ProductSet.test_prod%}{{product.title}} {% endfor %}{% else %}MOE_NOT_SEND{% endif %}"
}
},
"user_details": {
"identifier": "ID",
"identifier_value": "JOHN012"
}
}'
Sample Response
{
"personalized_content": {
"payload": {
"user_attribute_personalization": "<!DOCTYPE html>\n<html>\n<head>\n<title>User Profile Update Example</title>\n</head>\n<body>\n<p>Hi ,\n Your profile has been updated successfully.\n</p>\n<p>Here are your updated details:\n First Name: \n Last Name: \n Email: \n Mobile: \n Gender: Female\n</p>\n</body>\n</html>"
}
}
}
{
"personalized_content": {
"payload": {
"event_attribute_personalisation": "<!DOCTYPE html>\n<html>\n<head>\n<title>User Profile Update Example</title>\n</head>\n<body>\n<p>Hi ,\n Your profile has been updated successfully.\n</p>\n<p>Here are your updated details:\n event_attribute_1: \n App_Version: 1.0.2\n Email: \n Mobile: \n Gender: Female\n</p>\n</body>\n</html>"
}
}
}
{
"personalized_content": {
"payload": {
"data": [
{
"meta_info": {
"platform": [
"ANDROID"
],
"template_style": "BASIC",
"template_id": "12356733",
"template_name": "test_template",
"template_version": "1",
"created_by": "john.doe@example.com",
"channel": "PUSH",
"template_source": "API",
"template_type": "CUSTOM"
},
"external_template_id": "5b7d04c6-8ddc-49rw-80d9-c67266079609",
"version": 1,
"ANDROID": {
"basic_details": {
"title": "Test_custom_template_title",
"message": "Testing_message",
"default_click_action": "DEEPLINKING",
"default_click_action_value": "https://www.google.com",
"key_value_pairs": [
{
"key": "q",
"value": "tree"
}
]
},
"buttons": [
{
"btn_name": "btn1",
"click_action_type": "RICH_LANDING",
"click_action_name": "RICH_LANDING",
"click_action_value": "https://www.google.com",
"key_value_pairs": [
{
"key": "q",
"value": "cat"
}
]
},
{
"btn_name": "btn2",
"click_action_type": "DEEPLINKING",
"click_action_name": "DEEPLINKING",
"click_action_value": "https://www.google.com",
"key_value_pairs": [
{
"key": "q",
"value": "bat"
}
]
}
],
"advanced": {
"coupon_code": "QWERTY",
"icon_type_in_notification": "appicon",
"auto_dismiss_notification": true,
"dismissal_time_value": 1,
"dismissal_time_multiplier": "hours"
}
},
"created_by": "john.doe@example.com",
"created_at": "2024-01-30T13:50:51.044000",
"updated_by": "john.doe@example.com",
"updated_at": "2024-01-30T13:50:51.044000"
}
]
}
}
}
{
"personalized_content": {
"payload": {
"content_block": "first content block\nedited Hi there ! this is api testing for content block "
}
}
}
{
"personalized_content": {
"payload": {
"content_api": "{'coord': {'lon': 77.2167, 'lat': 28.6667}, 'weather': [{'id': 721, 'main': 'Haze', 'description': 'haze', 'icon': '50d'}], 'base': 'stations', 'main': {'temp': 302.2, 'feels_like': 301.06, 'temp_min': 302.2, 'temp_max': 302.2, 'pressure': 1011, 'humidity': 30, 'sea_level': 1011, 'grnd_level': 986}, 'visibility': 2500, 'wind': {'speed': 3.6, 'deg': 290}, 'clouds': {'all': 0}, 'dt': 1731667426, 'sys': {'type': 1, 'id': 9165, 'country': 'IN', 'sunrise': 1731633244, 'sunset': 1731671860}, 'timezone': 19800, 'id': 1273294, 'name': 'Delhi', 'cod': 200}"
}
}
}
{
"personalized_content": {
"payload": {
"product_set": "Brown Rang Banana Chocolate Zomato Wine Honey_Singh Onion Mango Cookies Bread Toffee "
}
}
}
Response Code Structure
{
"personalized_content": {
"payload": {
"First Name": "User1"
}
}
}
{
"error": {
"message": "Invalid Request",
"details": [
{
"target": "channel",
"message": "channel - Field is required but value is None : None"
}
]
}
}
{
"error": {
"message": "Invalid Request",
"details": [
{
"target": "MOE-APPKEY",
"message": "Invalid MOE-APPKEY used in Authentication Header"
}
]
}
}
{
"error": {
"message": "Rate limit reached",
"details": [
{
"message": "Rate Limit Exceeded. You have made too many requests in a short period."
}
]
}
}
{
"error": {
"message": "Server Error",
"details": {
"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
Yes, you can use custom templates with the Personalization Preview. The API will personalize the content within the template based on the user identifier provided and return the personalized HTML as a response.
Yes, you can pass event details as input to the API. Ensure the event name matches the one in your workspace.