Test a Campaign

You can use the Test Campaign API to test a campaign in MoEngage.

info

Information

  • Currently, you can use this API to test Email campaigns only.
  • You can test only those Email campaigns that are created using the Create Campaigns API.

API Endpoint

API Endpoint
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 bmF2ZWVua3VtYXI6bW9lbmdhZ2U="}

You can obtain the username and password details from the MoEngage Dashboard.

  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 tile to copy the API key.
  3. 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.

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.
basic_details Required JSON Object This object contains the basic details of the campaign. For more information, refer to Basic Details.
connector Required JSON Object

This object contains the connector details. For more information, refer to Connector Details.

campaign_content Required JSON Object This object contains the campaign content. For more information, refer to Campaign Content.
utm_params Optional JSON Object This object contains the UTM parameters details. For more information, refer to UTM Parameters.
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 of this API, 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.
  • You can use this API only for 10 users at a time.
  • The same personalization details are used across all users. For example, you pass the first name as Dave in personalization details, you have used the first name in the content, and there are 10 users. In this case, all 10 users will get the same first name (Dave).

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:

  • EMAIL
  • ID
  • CUSTOM_SEGMENT
  • MOBILE_NUMBER
identifier_values Required Array

This field denotes the identifier values.

Note: If you pass an email ID as identifier, your content will not be personalized using the data present in user profile.

locale_name Optional String This field denotes the locale name.
variation Optional String This field denotes the number of variations.

Response

Key Data Type Description
message JSON Object This field contains a brief description of the request status in the case of success. 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:

  • code - This field is of String type and contains the error code that provides a brief explanation of the error. 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 is of String type and describes why the request has failed.
  • details - This object provides the error details and contains the following information:
    • target - This field is of String type and denotes the target of the error.
    • message - This field is of String type and describes why the request has failed.
  • request_id: This field denotes the request ID.

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:

  • data - This object contains the data. For more information, refer to Data.
  • message - This field contains the success message.

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

Key Values Description
user_identifier(custom segment) JSON Object

This object contains the user ID (custom segment). It has the following fields:

  • status - String
  • failure_reason (if any) - String
email_id JSON Object

This object contains the email ID. It has the following fields:

  • status - String
  • failure_reason (if any) - String
UID JSON Object

This object contains the unique ID. It has the following fields:

  • status - String
  • failure_reason (if any) - String

Sample cURL Request

The following are codes to test:

  • Campaigns with with locate and variation
  • Campaigns with with personalization
Locale and Variation Personalization
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-raw '{
    "request_id": "uuid2",
    "channel": "EMAIL",
    "basic_details": {
        "name": "Test campaign",
        "team": "TestTeam",
        "tags": [
            "all users",
            "activation"
        ],
        "user_attribute_identifier": "MOE_EMAIL_ID",
        "subscription_category": "k8s_sanithy",
        "business_event": "",
        "content_type": "PROMOTIONAL"
    },
    "connector": {
        "connector_type": "SENDGRID",
        "connector_name": "Sample_Connector"
    },
    "campaign_content": {
        "content": {
            "Default": {
                "variation_1": {
                    "email": {
                        "attachments": [
                            {
                                "file_type": "URL",
                                "url": "https://www.google.com"
                            }
                        ],
                        "bcc_ids": [],
                        "cc_ids": [],
                        "from_address": "john.doe@example.com",
                        "html_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(221, 221, 221);\n }\n\n \t\t\t</style></head><body aria-disabled=\"false\" data-gr-ext-installed=\"\" data-new-gr-c-s-check-loaded=\"14.1184.0\" data-new-gr-c-s-loaded=\"14.1184.0\"><p> <a href=\"https://www.earlysalary.com/products/instant-cash/\">linkper</a></p></body></html>",
                        "preview_text": "personalization_details",
                        "reply_to_address": "john.doe@example.com",
                        "sender_name": "personalization_details",
                        "subject": "personalization_details"
                    }
                },
                "variation_2": {
                    "email": {
                        "attachments": [
                            {
                                "file_type": "URL",
                                "url": "https://www.google.com"
                            }
                        ],
                        "bcc_ids": [],
                        "cc_ids": [],
                        "from_address": "john.doe@example.com",
                        "html_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(221, 221, 221);\n }\n\n \t\t\t</style></head><body aria-disabled=\"false\" data-gr-ext-installed=\"\" data-new-gr-c-s-check-loaded=\"14.1184.0\" data-new-gr-c-s-loaded=\"14.1184.0\"><p> <a href=\"https://www.earlysalary.com/products/instant-cash/\">linkper</a></p></body></html>",
                        "preview_text": "personalization_details",
                        "reply_to_address": "john.doe@example.com",
                        "sender_name": "personalization_details",
                        "subject": "personalization_details"
                    }
                }
            },
            "revivallocale": {
                "variation_1": {
                    "email": {
                        "attachments": [
                            {
                                "file_type": "URL",
                                "url": "https://www.google.com"
                            }
                        ],
                        "bcc_ids": [],
                        "cc_ids": [],
                        "from_address": "john.doe@example.com",
                        "html_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(221, 221, 221);\n }\n\n \t\t\t</style></head><body aria-disabled=\"false\" data-gr-ext-installed=\"\" data-new-gr-c-s-check-loaded=\"14.1184.0\" data-new-gr-c-s-loaded=\"14.1184.0\"><p> <a href=\"https://www.earlysalary.com/products/instant-cash/\">linkper</a></p></body></html>",
                        "preview_text": "personalization_details",
                        "reply_to_address": "john.doe@example.com",
                        "sender_name": "personalization_details",
                        "subject": "personalization_details"
                    }
                },
                "variation_2": {
                    "email": {
                        "attachments": [
                            {
                                "file_type": "URL",
                                "url": "https://www.google.com"
                            }
                        ],
                        "bcc_ids": [],
                        "cc_ids": [],
                        "from_address": "john.doe@example.com",
                        "html_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(221, 221, 221);\n }\n\n \t\t\t</style></head><body aria-disabled=\"false\" data-gr-ext-installed=\"\" data-new-gr-c-s-check-loaded=\"14.1184.0\" data-new-gr-c-s-loaded=\"14.1184.0\"><p> <a href=\"https://www.earlysalary.com/products/instant-cash/\">linkper</a></p></body></html>",
                        "preview_text": "personalization_details",
                        "reply_to_address": "john.doe@example.com",
                        "sender_name": "personalization_details",
                        "subject": "personalization_details"
                    }
                }
            },
            "utm_params": {
                "utm_source": "Moengage",
                "utm_medium": "{{Campaign Channel}}",
                "utm_campaign": "{{Campaign Id}}!{{Campaign Delivery Type}}",
                "utm_content": "{{Campaign Tags id}}",
                "utm_campaign_ID": "{{Campaign Id}}",
                "utm_locale": "{{Locale Name}}",
                "utm_var": "{{Variation Name}} test",
                "utm_custom": "custom"
            },
            "personalization_details": {
                "user_attributes": {
                    "pers_attr_1": {},
                    "pers_attr_2": {},
                    "pers_attr_3": {}
                },
                "event_attributes": {
                    "pers_attr_1": {},
                    "pers_attr_2": {},
                    "pers_attr_3": {}
                }
            },
            "test_campaign_meta": {
                "identifier": "EMAIL",
                "identifier_values": [
                    "john.doe@example.com",
                    "harry.doe@example.com",
                    "nick.doe@example.com"
                ],
                "locale_name": "revivallocale",
                "variation": "variation_2"
            }
        }
    }}'

Sample Response

200 400 401 500
{
    "data": {
        "Test_list_user": {
            "status": "success"
        }
    },
    "message": "Test campaign created successfully"
}

Postman Collections

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

FAQs

arrow_drop_down Can I send the test email to IDs that are not the part of MoEngage?

Yes, you can send the test campaign to any user by passing identifier as "Email". The campaign sent will not be personalised.

arrow_drop_down How does personalisation works if I pass only a subset of user attribute values used under the content for personalisation?

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.

Previous

Next

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

How can we improve this article?