Overview
Content APIs help you create highly personalized marketing campaigns. They fetch dynamic data, like product recommendations, coupons, or user preferences, at the moment a message is sent. This means each recipient gets content specifically tailored to them, leading to much better engagement and conversion rates compared to generic campaigns. Marketers and product managers use Content APIs to deliver timely, relevant messages and enhance the customer experience.
For example, if a user books a flight, you can use Dynamic Content APIs to send them an email with offers on hotel accommodation for the destination, within a few hours of booking the flight. The API can consider their accommodation preferences.
Such targeted, relevant, and timely communication helps drive conversions and uncover opportunities for upsell and cross-sell.
If a user adds items to their shopping cart but does not complete the purchase (like a hotel room in Bali), a Content API can trigger an email. This email reminds them to complete the transaction and recommends similar hotels. Targeted, contextual, and personalized emails like this are an extremely useful tool for a marketer looking to grow their business.
Before You Begin
To use Content APIs effectively, ensure you have:
- A basic understanding of APIs and how they work (you can collaborate with your development team).
- Familiarity with creating campaigns in MoEngage.
- Knowledge of JINJA templating language for advanced content personalization.
| info |
Information If your API endpoints are in a Virtual Private Cloud (VPC) or are not publicly accessible, you must whitelist these MoEngage IPs, depending on your Workspace's region. |
Using Content APIs in MoEngage
MoEngage helps you deliver rich, personalized, and timely messages to your customers. Here is the general process to use Content APIs for your campaigns:
- Configure an external API in MoEngage (a technical step).
- Create a personalized campaign using the data fetched by the API (a marketing step).
- Run and monitor the campaign.
Step 1: Add a Content API
To set up an API for use in MoEngage campaigns, refer to Add a Content API.
Note: While using Content APIs to personalize campaigns is a powerful tool for marketers, the initial setup of these APIs within MoEngage often involves technical details. This may require collaboration with your development team to configure the API. After the API is configured, marketers can then leverage the fetched data in their campaigns using Jinja.
Step 2: Use Content APIs in Campaigns
Once the Content API is configured and tested by your technical team, you can begin creating campaigns using any existing content templates that include API calls embedded within the content. These campaigns can contain placeholders for different SKUs (in this case, hotels), with the required formatting, segmentation, and triggering schedules. You will use Jinja templating language to insert the data fetched from the API into your campaign messages.
Content APIs can be added to the campaigns sent using the following channels:
For more information on personalizing content using content APIs (that is, using Jinja with the fetched data), refer to Personalize Content Using Content APIs.
Example of Content API
Marketers want to use weather-related information to target users in a specific geographic area for an email campaign. In the example below, a marketer from an e-commerce company wishes to drive sales for the Autumn line of products (scarves, boots, coats, and what have you) that the company is promoting in London by sending an email campaign. The marketer utilizes a Content API that retrieves weather information for London and incorporates it into the content section during campaign creation.
Step 1: Configure the Example Content API
Configuring any Content API, including this weather example, involves specifying how MoEngage should connect to and request data from an external source. This requires understanding the external API's documentation regarding endpoints, necessary parameters (like API keys or location identifiers), and the structure of the data it returns.
Note: While this example walks through the configuration in MoEngage, your developer or technical team member will typically handle this setup, ensuring that all technical requirements of the external API (such as OpenWeatherMap in this case) are met.
To configure the Content API within MoEngage, perform the following steps:
- On the left navigation menu in the MoEngage UI, go to Settings > Advanced Settings > Content API.
- Click + Add content API in the upper-right corner. The Add content API pane appears.
- In step 1, Add details, configure the API.
We have used the following API to fetch the weather details using a weather API. The API takes in two parameters the APPID (this is the Application ID of the Weather API we have used, which has been hosted on a 3rd party site) and the city name.- API name: Enter a name for the API. For example, Weather.
- Method: Select the method.
-
Url: Enter the URL of the API. For example,
http://samples.openweathermap.org/data/2.5/weather
Note: This is a sample URL. For live data, use a production OpenWeatherMap endpoint. - Enter the parameters to be passed.
- In this example, the parameters added are the city name (
qfor OpenWeatherMap) and the APPID (appid). The city name can either be static (for example, "London,uk"), or this can be personalized and fetched from the user attributes by entering '@' in the Value textbox and selecting the attribute. - The user's city will be fetched using personalization while sending the campaign (when the user attribute city is chosen using personalization, this is represented as {{UserAttribute['LastKnownCity']}} in the value text field).
- In this example, the parameters added are the city name (
- Click Save. You are taken to step 2, API response.
- Under Mask PII fields, select Yes.
To mask PII fields from the API response shown in MoEngage logs or UI, select Yes for PII masking and then choose the preferred field names for which you want to mask the information. You can now mask PII values from Content API output. For more information, see here. - Click Done. After the Content API is saved, it is added to the Content API search listing. You can now use it to create content for any campaign.
Step 2: Test the Content API
Test the Content API to ensure it fetches the correct data.
- On the Content API page, click the Content API created (for example, "Weather") in the search listing of the Content API screen.
- Click the ellipses icon
at the end of the row and then click Test.
- In the Test content API pane, enter values for the parameters (for example, "London,uk" for city, and a valid API key for "appid").
- Click Test in the bottom-right corner. This sends the parameters to the configured Content API and shows the generated response.
Note: In this example, we use the Content API with a static parameter for the city name. - The JSON response for this API (assuming a successful call to OpenWeatherMap for London) is shown below:
{ "weather": [ { "description": "light intensity drizzle" } ], "coord": { "lat": 51.51, "lon": -0.13 }, "base": "stations", "dt": 1485789600, "main": { "pressure": 1012, "temp_min": 279.15, "temp_max": 281.15, "temp": 280.32, "humidity": 81 }, "id": 2643743, "wind": { "speed": 4.1, "deg": 80 }, "cod": 200 }
This response contains details like description, wind speed, humidity, and temperature. For this example, the weather description is "light intensity drizzle". You can parse this response using JINJA to use it in your content creation
Step 3: Use the Content API in Campaign Content
Create a one-time email campaign, select your target segment, and follow these steps in the content creation stage (step 2 of campaign creation):
- Choose your desired template. For this example, we selected an e-commerce template with product recommendations for the autumn line.
- Type your content in the text area.
- For this email campaign, we used the following sample text:
"The weather is inclement and the forecast for the next few days is <add content API call and parse the response to get the description detail from the API>.
Why venture out for shopping when you can take a look at our top picks for you from the cozy confines of your home?"
- Use the following JINJA code to call the 'Weather' Content API:
{%set weatherAPI = ContentApi.Weather({ ({"params":{"q":"London,uk","appid":""}, "static_params":{},"dynamic_params":{},"request_body":{}}) }) %}This JINJA code assigns the JSON response from the Content API to the
weatherAPIvariable. - To extract the weather description from the
weatherAPIvariable, use the following JINJA code:{% for weather in weatherAPI.weather %} {{weather.description}} {% endfor %}This code iterates through the "weather" array in the JSON response and prints the "description" field.
- Add product recommendations and other necessary content. In the upper-right corner of the editor, click Preview. The preview screen opens.
- In the top pane, click the Personalized tab to see the personalized content.
Note: We did not add any user-specific personalization in this example. However, the Content API is executed, and the weather information is fetched and used in the content, as shown below. If you personalize any user attributes, they will be fetched for a random user from your chosen campaign segment. For more details, refer to Personalization Overview. - Select delivery schedules and goals in the next step of the campaign, then publish the campaign.
Frequently Asked Questions
Yes. If a Content API call fails due to a timeout, MoEngage retries the request up to three times. The maximum API timeout limit is five seconds.
MoEngage divides the total number of users in a campaign into multiple batches, which are processed in parallel. Within each batch, API calls are made sequentially.
Example: Consider two campaigns, C1 (with 1 million users) and C2 (with 2 million users), which start simultaneously. If the batch size is 500, the total number of batches for both campaigns is (1M + 2M) / 500 = 6000 batches. If 100 machines are used for API calls, and each machine has 10 processes, 1000 API calls can go out in parallel. Calls for each batch of 500 happen sequentially, but 1000 API calls run in parallel at any given time.
Note: The batch size and the maximum number of machines used vary by channel. This example illustrates how MoEngage makes Content API calls, rather than specifying channel limits.
To enable OAuth, contact your Customer Success Manager or the MoEngage Support team.
The Auth Token service supports the Authorization Code grant type and Client Credential grant type APIs. For more information, refer to Application Grant Types.
The APIs used for authentication should include an expiry time for the token in their response. This expiry time can be in seconds, minutes, hours, or as an exact epoch timestamp. MoEngage uses this information to automatically manage token refresh.
For further assistance, please contact your MoEngage Customer Success Manager (CSM) or the Support team.