You can use this API to test a campaign in MoEngage.
info |
Information
|
API Endpoint
Method: POST
https://api-0X.moengage.com/core-services/v1/campaigns/test
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 Base64_ENCODED_APPKEY_APIKEY"}
You can obtain the username and password details from the MoEngage UI.
- 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 Base64_ENCODED_APPKEY_APIKEY=="} |
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 UI:
Settings -> Account -> APIs -> Workspace ID (earlier app id) For more information, refer to Authentication. |
Request Body
Key | Required | Values | Description |
---|---|---|---|
request_id | Required | String | This field denotes the request ID for which the campaign is tested. |
channel | Required | String | This field denotes the type of channel. Supported value is PUSH. |
basic_details | Required | JSON Object | This object contains the basic details of the campaign. For more information, refer to Basic Details. |
campaign_content | Required | JSON Object | This object contains the campaign content. For more information, refer to Campaign Content. |
personalization_details | Optional | JSON Object | This object contains the personalization details. For more information, refer to Personalization Details. |
test_campaign_meta | Required | JSON Object | This object contains the test campaign meta details. For more information, refer to Meta Info. |
Personalization Details
info |
Information When you pass personalization details in the personalization_details object, MoEngage uses those details to personalize the user attributes or event attributes present in the content instead of the attributes present in the user profile. |
The personalization_details JSON object contains the following information:
Key | Required | Values | Description |
---|---|---|---|
user_attributes | Optional | JSON Object | This object contains personalization details for user attributes. |
event_attributes | Optional | JSON Object | This object contains personalization details for event attributes. |
Meta Info
The meta_info JSON object contains the following information:
Key | Required | Values | Description |
---|---|---|---|
identifier | Required | String |
This field denotes the identifier. Supported values are:
|
identifier_values | Required | Array |
This field denotes the identifier values. |
locale_name | Optional | String | This field denotes the locale name. |
variation | Optional | String | This field denotes the name of the variation. |
Response
Key | Data Type | Description |
---|---|---|
message | String | This field contains a brief description of the request status if it is successful. For more information, refer to Response Codes. |
error | JSON Object |
This field contains the reason for the request's failure. Structure: "error": { "code": "<error_code>", "message": "<error_message>", "target": "<target>", "details": [ { "target": "<target>", "message": "<error_message>" } ], "request_id": "<request_id>" } } 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. This JSON object has the following structure:
|
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 |
Authentication Failure |
This response is returned when the authorization parameters are missing in the HTTP Auth Header. |
500 |
Internal Server Error |
This response is returned when the system runs into an unexpected error. |
Data
The Data JSON object contains the following information:
Key | Values | Description |
---|---|---|
user_identifier(custom segment) | JSON Object |
This object contains the user ID (custom segment). It has the following fields:
|
email_id | JSON Object |
This object contains the email ID. It has the following fields:
|
UID | JSON Object |
This object contains the unique ID. It has the following fields:
|
Sample cURL Request
The following is the sample code to test the Push campaigns:
curl --location 'https://api-0X.moengage.com/core-services/v1/campaigns/test' \
--header 'MOE-APPKEY: {{Workspace_ID or APP_ID}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic {{Authorization_Key}}' \
--data '{
"request_id": "{{request_id}}",
"channel": "PUSH",
"basic_details": {
"name": "{{campaign_name}}",
"team": "{{team_name}}",
"platforms": [
"IOS"
],
"platform_specific_details": {
"ios": {
"send_to_all_eligible_device": true,
"exclude_provisional_push_devices": false,
"send_to_only_provisional_push_enabled_devices": false
}
}
},
"campaign_content": {
"content": {
"push": {
"ios": {
"template_type": "SIMPLE_IMAGE_CAROUSEL",
"basic_details": {
"background_color_code": "#a0a0a0",
"apply_background_color_in_text_editor": false,
"title": "Message Carousel Check",
"message": "Sample Check",
"subtitle": "Subtitle",
"allow_bg_refresh": true,
"default_click_action": "DEEPLINKING",
"default_click_action_value": "string",
"key_value_pairs": [
{
"key": "keyy",
"value": "valuee"
}
],
"carousel_content": {
"slider_transition": "MANUAL",
"slide_data": [
{
"image_url": "string",
"image_click_action": "DEEPLINKING",
"image_click_action_value": "string",
"key_value_pairs": [
{
"key": "tree",
"value": "dance"
}
]
},
{
"image_url": "image_url.jpg",
"image_click_action": "DEEPLINKING",
"image_click_action_value": "image_click_action_value.jpg",
"key_value_pairs": [
{
"key": "tree",
"value": "dance"
}
]
},
{
"image_url": "image_url.jpg",,
"image_click_action": "DEEPLINKING",
"image_click_action_value": "image_click_action_value.jpg",
"key_value_pairs": [
{
"key": "tree",
"value": "dance"
}
]
}
]
}
},
"advanced": {
"coupon_code": "Coupon code",
"sound_file": "Sound",
"enable_ios_badge": true
},
"template_backup": {
"title": "Message backup title",
"message": "Message backup",
"subtitle": "Subtitle backup",
"allow_bg_refresh": true,
"rich_media_type": "Image",
"rich_media_value": "https:/2017/01/random.jpg",
"default_click_action": "DEEPLINKING",
"default_click_action_value": "https://default_click_action_value/2017/01/random.jpg",
"key_value_pairs": [
{
"key": "keyy2",
"value": "valuee2"
}
]
}
}
}
}
},
"test_campaign_meta": {
"identifier": "USER_ATTRIBUTE_UNIQUE_ID",
"identifier_values": [
"john012"
]
}
},
{
"request_id": "{{request_id}}",
"channel": "PUSH",
"basic_details": {
"name": "{{campaign_name}}",
"team": "{{team_name}}",
"platforms": [
"ANDROID",
"IOS",
"WEB"
],
"platform_specific_details": {
"ios": {
"send_to_all_eligible_device": true,
"exclude_provisional_push_devices": false,
"send_to_only_provisional_push_enabled_devices": false
}
}
},
"campaign_content": {
"content": {
"push": {
"android": {
"template_type": "BASIC",
"basic_details": {
"notification_channel": "general",
"title": "quick scheduled update",
"message": "Message",
"summary": "Message summary",
"image_url": "{{image_url}}",
"default_click_action": "DEEPLINKING",
"default_click_action_value": "{{default_click_action_value}}",
"key_value_pairs": [
{
"key": "q",
"value": "adfsa"
}
]
},
"buttons": [
{
"btn_name": "Button 1.1",
"click_action_type": "DEEPLINKING",
"click_action_name": "asd",
"click_action_value": "{{click_action_value}}",
"key_value_pairs": [
{
"key": "q",
"value": "adfsa"
}
]
},
{
"btn_name": "button2.1",
"click_action_type": "RICH_LANDING",
"click_action_name": "asd",
"click_action_value": "{{click_action_value}}",
"key_value_pairs": [
{
"key": "q",
"value": "adfsa"
}
]
}
],
"advanced": {
"coupon_code": "Coupon code 24",
"icon_type_in_notification": "app_icon",
"auto_dismiss_notification": true,
"auto_dismiss_notification_time_value": 1,
"auto_dismiss_notification_time_granularity": "DAYS"
}
},
"ios": {
"template_type": "SIMPLE_IMAGE_CAROUSEL",
"basic_details": {
"background_color_code": "#a0a0a0",
"apply_background_color_in_text_editor": false,
"title": "Test API title",
"message": "Sample Check",
"subtitle": "Subtitle",
"allow_bg_refresh": true,
"default_click_action": "DEEPLINKING",
"default_click_action_value": "https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg",
"key_value_pairs": [
{
"key": "keyy",
"value": "valuee"
}
],
"carousel_content": {
"slider_transition": "MANUAL",
"slide_data": [
{
"image_url": "https://www.gstatic.com/webp/gallery/5.jpg",
"image_click_action": "DEEPLINKING",
"image_click_action_value": "https://www.gstatic.com/webp/gallery/2.jpg",
"key_value_pairs": [
{
"key": "tree",
"value": "dance"
}
]
},
{
"image_url": "https://www.gstatic.com/webp/gallery/2.jpg",
"image_click_action": "DEEPLINKING",
"image_click_action_value": "https://www.gstatic.com/webp/gallery/2.jpg",
"key_value_pairs": [
{
"key": "tree",
"value": "dance"
}
]
},
{
"image_url": "https://www.gstatic.com/webp/gallery/3.jpg",
"image_click_action": "DEEPLINKING",
"image_click_action_value": "https://www.gstatic.com/webp/gallery/2.jpg",
"key_value_pairs": [
{
"key": "tree",
"value": "dance"
}
]
}
]
}
},
"advanced": {
"coupon_code": "Coupon code",
"sound_file": "Sound",
"enable_ios_badge": true
},
"template_backup": {
"title": "Message backup title",
"message": "Message backup",
"subtitle": "Subtitle backup",
"allow_bg_refresh": true,
"rich_media_type": "Image",
"rich_media_value": "https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg",
"default_click_action": "DEEPLINKING",
"default_click_action_value": "https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg",
"key_value_pairs": [
{
"key": "keyy2",
"value": "valuee2"
}
]
}
},
"web": {
"template_type": "BASIC",
"basic_details": {
"title": "Sample Check",
"message": "Kannada - ಶುಭೋದಯ Hindi - शुभ प्रभात, आपका दिन अच्छा हो| ",
"redirect_url": "https://www.gstatic.com/webp/gallery/1.jpg",
"auto_dismiss_notification": true,
"image_url": "https://www.gstatic.com/webp/gallery/2.jpg"
},
"buttons": [
{
"title": "Button-1",
"icon_url": "https://www.gstatic.com/webp/gallery/1.jpg",
"url": "https://www.gstatic.com/webp/gallery/2.jpg"
}
],
"advanced": {
"icon_image_type": "DEFAULT"
}
}
}
}
},
"test_campaign_meta": {
"identifier": "CUSTOM_SEGMENT",
"identifier_values": [
"cdsghdsgqa"
]
}
}
Sample Response
{
"data": {
"Test_list_user": {
"status": "success"
}
},
"message": "Test campaign created successfully"
}
{
"error": {
"code": "400 Bad Request",
"message": "request_id key is mandatory field",
"details": [
{
"target": "request_id",
"message": "request_id key is mandatory field"
}
],
"request_id": "11"
}
}
{
"error": {
"code": "401 Authentication error",
"message": "Authentication required",
"details": [
{
"code": "InvalidValue",
"target": "APP_SECRET_KEY",
"message": [
{
"code": "InvalidValue",
"target": "APP_SECRET_KEY",
"message": "Invalid APP_SECRET_KEY is provided."
}
]
}
],
"request_id": ""
}
}
{
"error": {
"code": "500 Internal Server Error",
"message": "Something went wrong. Please contact Moengage team",
"target": "string",
"details": [
{
"message": "Expecting value: line 1 column 1 (char 0)",
"target": ""
}
]
}
}
Postman Collections
We have made it easy for you to test the APIs. Click here to view it in Postman.
FAQs
Yes, you can send the test campaign to any user by passing identifier as "Email". The campaign sent will not be personalised.
The values passed under personalisation details will be used for all users to whom the test campaign to be sent and the remaining user attributes values will be picked up from the user profile.