Push API

Push API is used to:

  • Create Campaigns (targeting all users or a group of users) to send notifications.
  • Target a single user using a unique user attribute
  • Personalize payload for each user.

API Endpoint

URL
POST https://api-0X.moengage.com/v2/transaction/sendpush

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 here.

Request Headers

HTTP
'Content-Type':'application/json'

Request Body

  • appId (Mandatory: Yes)
    • APP ID provided by MoEngage to identify the specific app. You can find it under Settings -> Transactional Push Settings on MoEngage Dashboard. MoEngage recommends that you test API integration on Test Environment. The App Id for TEST ACCOUNT is suffixed with _DEBUG.
  • campaignName (Mandatory: Yes)
    • Used to check the campaign details/statistics on the MoEngage dashboard. Campaign name should be unique for All Users & Custom Segment campaigns. For User Level API requests:
      campaign name should be the same if multiple requests belong to a single type of campaign.
      campaign names should be unique if all the API requests belong to different campaign types.
      NOTE: API automatically creates a campaign with the given name. You need not create a campaign from the dashboard to use the name.
  • signature (Mandatory: Yes)
    • A signature is required to verify if the client is authorized to make the API call. It is generated from a hash of Campaign Name, App Id and API Secret. You can find API Id (or App Id) & API Secret in your MoEngage Dashboard under Settings->Transaction Push Settings
  • requestType
    • The value of this key is used to indicate the intention of an API request. The default value is push.
  • targetAudience (Mandatory: Yes)
    • The target segment for the campaign. It can have one of the following values

      • All Users: to target all users of your App/Website

      • Custom Segment: to target pre-created user segments. You will have to use the MoEngage dashboard to create/manage custom segments. Please note that the custom segment name should exactly match the name of the target segment on the MoEngage dashboard

      • User: to target a user with an attribute

  • customSegmentName (Mandatory if the targetAudience value is Custom Segment)
    • Name of the custom segment as saved or defined on the dashboard
  • targetUserAttributes (Mandatory if targetAudience value is User)
    • In case the target audience is the User, you can target the user via user properties/attributes. You have to send the following parameters to find the user
      - attribute
      - comparison parameter
      - attribute value

      Note:
      For API Requests where the target audience is a specific user, if a campaign with the given name already exists, existing campaign data corresponding to the given campaign name will be used for sending notifications.
      Any edits in other parts of campaign data within the API request parameters will be ignored.
      If any changes are required in the campaign data, please change the name of the campaign in API Request, so that a new campaign is created.

      Note:
      For targeting over 100 users via user attribute:
      bulkUserRequest - “true”,
      requestId - Mandatory, should be unique for each request.
  • targetPlatform (Mandatory: Yes)
    • To choose the platform devices being targeted by your campaign. Push API allows you to target users on Android app, iOS app, and Web platforms. You can target one or more platforms. If you are sending Web (Chrome) push notifications through the API, you should choose Web as the platform.
  • payload (Mandatory: Yes)
    • Enables push messages and rich content (image, sound and so on) sent to your customers. Do the following:
      1. Configure messages separately to the target platforms you want to send.
      2. Include payload for at-least one platform in your API request.

      Rich Content supported on different platforms are as follows.
      ANDROID - coupon, image, sound
      IOS - coupon, sound, image, audio, video ( image, video, and audio are only supported after IOS-10)
      WINDOWS - coupon

      To use emoticons (emojis), just copy-paste it where required (ex. ❤️ )
      Note: image, video, and audio can not be used together.

  • campaignDelivery (Mandatory: Yes)
    • Helps decide when the campaign should be sent.
      All notifications targeted to a single user will be sent as soon as possible (ASAP).
      Scheduling campaign for Later or Periodically is applied only for segmented or all users campaigns.
  • defaultAction (Mandatory: Yes for Android and Web. Optional for iOS)
    • Different deep-linking options for the Android/iOS platform. You can define the action when the user clicks on the notification through this.
  • conversionGoals
    • List of conversion goals. Once set it can't be changed for a specific campaign.

      For numeric attributes, allowed filter types are:
      [ ‘is between’, ‘is less than, ‘is greator than’, is equal to` ]
  • advancedSettings
    • Advanced settings for the push include settings like TTL ( time to live), ignoreFC, countFC, and priority of the message.
  • TTL
    • If not delivered, Push Services(GCM/APNS) will retry to send the message until the TTL (in hours) does not expire. Send ‘0’ if it is not applicable for you. After TTL has expired, push notifications will not be shown to the user. The default value for TTL is 36 hours and is applicable only to Android push / Web push notifications.
  • ignoreFC
    • Values are "true" or "false".
      "true" value - Bypasses Frequency capping set using the dashboard and will send the notifications to everyone in the target segment.
      "false" value - Applies the Frequency cap set on the dashboard and will not send the notification after the limit is reached.
      If the key is not present, it will be treated as ignoreFC="False". While testing your API, ensure that you set this flag as "true" else you might not receive a few notifications.
  • countFC
    • Values are "true" or "false" only when ignoreFC value is set to true.
      "true" value - Only push campaigns are counted in frequency cap count.
      "false" value - Push campaigns are not counted in the frequency cap count.
  • sendAtHighPriority
    • Values are "true" or "false" only for Android push / Web push notifications. Uses GCM/FCM flag to send time critical messages with high priority and drains user's device battery more than normal messages.
  • pushAmp+
  • preCacheSegment
    • Values are "true" or "false". Applicable for scheduled and periodic campaigns. If enabled, pre-caches the segmentation and campaign sending time will be improved. For caching, it is recommended to create the campaign at least 2 hours before the scheduled time.
  • campaignThrottleTime
    • Values are in integer (time in minutes). Push throttling allows you to control the rate of sending a push notification. The value to be passed can be between 1 and 360 (minutes).
  • useJinjaPersonalization
    • Values are "true" or "false". A boolean value to indicate if Jinja personalization is applied on the message payloads. Recommended using this personalization format.
  • ignoreMinimumDelay
    • Values are "true" or "false". A boolean value to indicate if Client level Minimum Delay setting is to be applied for the campaign. The default value is true, if not passed in the API.
  • additionalActions
    • Additional action buttons for Android. The buttons allowed for ANDROID are call, snooze, copy, and share. A maximum of two additional action buttons can be used at a time.

We have mentioned examples for some of the attributes.

campaignName

If you want to push updates to your users for Billing and Order Confirmation, all the push requests related to billing can have the same campaign name: “Billing Campaign” while all the push requests related to order delivery can have the campaign name “Orders Campaign”. As a result, one would be able to see aggregated stats for all related (All Billing or All Order Confirmation) API requests under one campaign name.

signature

Python code to generate the signature for your test account, use the app_id that is appropriate for your account.

3b8534b-1.png

# Python2.x
from hashlib import sha256
app_id = "MAZW51234N1IMMSH5HKBHK_DEBUG" #(Please refer to required parameters section)
campaign_name = "TEST"
api_secret = "S3pVzjBF9use" # This is the sample key. Each app has a different secret key
signature_key = app_id+'|'+ campaign_name+'|'+ api_secret
signature = sha256(signature_key).hexdigest()

# Python3.x
from hashlib import sha256
app_id = "MAZW51234N1IMMSH5HKBHK_DEBUG" #(Please refer to required parameters section)
campaign_name = "TEST"
api_secret = "S3pVzjBF9use" # This is the sample key. Each app has a different secret key
signature_key = app_id+'|'+ campaign_name+'|'+ api_secret
signature = sha256(signature_key.encode('utf-8')).hexdigest()

Generated Signature

Generated Signature: 
bc52a205a64d18d9978d9532a59f6302e2a5745bd1fda05929dd6f044a9fb7b3

 

targetAudience

User-based targeting is done based on fields as described in the example.
In the example, user email is used for user-based targeting.

// e.g. To target All Users
"targetAudience": "All Users",

// e.g. To target a custom segment with name: MySegment123
"targetAudience": "Custom Segment",
"customSegmentName": "MySegment123",

// e.g. To target an user with Email Id as abc@exmaple.com, it will be
"targetAudience": "User",
"targetUserAttributes": 
{
    "attribute": "USER_ATTRIBUTE_USER_EMAIL",
    "comparisonParameter": "is",
    "attributeValue": "abc@example.com"
},

Other fields used are:
for unique id use - USER_ATTRIBUTE_UNIQUE_ID
for email use - USER_ATTRIBUTE_USER_EMAIL
for mobile number use - USER_ATTRIBUTE_USER_MOBILE
for Google Advertising identifier - MOE_GAID
for iOS Identifier for advertising - ADVERTISING_IDENTIFIER
for device push token - PUSH_ID ( same key is used for android gcmId, iOS push token and windows channel uri)

For custom attributes, targeting is done on any custom attribute along with the available fields. Set the extra key, "isCustom" to true.
comparisonParameter supports only "is" and "in" query types.
The following example describes the custom attribute set to true.

 

targetPlatform

Target Single Platform Target Multiple Platform
//List of platforms to target
"targetPlatform":["ANDROID"],

 

payload

payload sample rich content
"payload": {
    "ANDROID": { // payload specific to Android
    },
    "IOS": { // payload specific to iOS
    },
    "WINDOWS": { // payload specific to Windows
     },
     "WEB": { // payload specific to web.
    }
 }

 

campaignDelivery

ASAP Schedule later Recurring Campaigns
// send campaign asap
"campaignDelivery": {
    "type": "soon"
  },

 

conversionGoals

single conversion goal multiple conversion goal
// single conversion goal 
"conversionGoals": [
    {
      "name": "amount 1", // name of the goal to be displayed in dashboard.
      "eventName": "AddedTocart", // event on which conversion should be tracked.
      "attrs": { // attributes of event.
        "filter": "is between",
        "name": "amount",
        "value": "10,100", //range to be passed as comma seperated values 
        "type": "numeric"
      }
    }
  ]

 

advanceSettings

// sample advanced settings

"advancedSettings": {
    "ttl": { // if not passed, all platforms will have ttl of 36 hours.
      "ANDROID": 12,
      "WEB": 24
    },
    "ignoreFC": "true",
  	"countFC": "true",
    "sendAtHighPriority": "true",
    "pushAmp+"       : "true",
    "preCacheSegment": "true",
    "campaignThrottleTime" : 5,
    "useJinjaPersonalization" : "true" ,
    "ignoreMinimumDelay"      : "false"
    
  }

 

defaultAction

"defaultAction": { // Default action when user click on notifications. 
  "type": "navigation",
  "value": "", // Value of the screen name on which re-direction should happen.
  "kvPairs" :{ // additional key value pairs to be passed while sending notification.
                       "key1" : "value1",
                        "Key2" : "value2"
             } //optional 
},

"defaultAction": { // Default action when user click on notifications. 
  "type": "richlanding",
  "value": "" ,// Rich landing url, which is a web (http/https) url.
  "kvPairs" :{ // additional key value pairs to be passed while sending notification.
                       "key1" : "value1",
                        "Key2" : "value2"
             } //optional 
},

"defaultAction": { // Default action when user click on notifications. 
  "type": "deeplinking",
  "value": "", // Deep-linking URI
  "kvPairs" :{ // additional key value pairs to be passed while sending notification.
                       "key1" : "value1",
                        "Key2" : "value2"
             } //optional 
},

 

additionalActions

"additionalActions": [ // List of action buttons. Maximum 2 buttons are allowed.
        {
          "type": "call",// action type
          "value": "12345678", // respective value
          "name": "Call button", // action name displayed on notification
          "iconURL": "abc" // url for icon to be displayed
        },
        {
          "type": "copy", // action type
          "value": "12345678", // respective value
          "name": "Copy button", // action name displayed on notification
          "iconURL": "abc" // icon url
        },
        {
          "type": "snooze", // action type
          "value": 5, // in hours i.e. snooze after 5 hours
          "name": "snooze button", // action name, displayed on notification
          "iconURL": "abc" // icon url
        },
        {
          "type": "share", // action type
          "value": "xyz", // text to share
          "name": "share button", // action name, displayed on notification
          "iconURL": "abc" // icon url
        }
      ]

Response

Response Code Description
200 Your request has been registered. You can check the dashboard for the campaign status.
4xx Kindly check the response for payload error information.
5xx There is something is wrong with the server, kindly retry the request after some time.

Sample Payloads 

Here are the sample payloads across different platforms (Android, iOS & Web).

Example 1

Android app iOS app web (Chrome Push) Windows app
"ANDROID": {
      "message": "Message", // Message of the push notification
      "title": "Title", // Title of the push notification 
  		"channel_id": "ChannelId", // Channel id of push notification (Optional)
      "richContent": [ //List of rich content items. Android push notifications have support  Image, Coupen and Sound. One single notifcations can support all combinations of these three types of rich content.
        {
          "type": "image",
          "value": "https://images.iimg.in/c" 
        },
        {
          "type": "coupon", 
          "value": "free" // when user click notifications, this code will be copied.
        },
        {
          "type": "sound",
          "value": "tring"
        }
      ],
      "defaultAction": { // Default action when user click on notifications. 
        "type": "richlanding", // Type of the default action
        "value": "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8 ",
        "kvPairs" :{ // additional key value pairs to be passed while sending notification.
        		"key1" : "value1",
        		"Key2" : "value2"
         }
      },
      "additionalActions": [ // List of action buttons. Maximum 2 buttons are allowed.
        {
          "type": "call",// action type
          "value": "12345678", // respective value
          "name": "Call button", // action name, displayed on notification
          "iconURL": "abc" // url for icon to be displayed
        },
        {
          "type": "copy", // action type
          "value": "12345678", // respective value
          "name": "Copy button", // action name, displayed on notification
          "iconURL": "abc" // icon url
        }
      ],
      "fallback": { // Complete replica of the android dict, in case a personalization is failed, this message content will be sent.
      }
    },

 

Example 2

 
This is a sample payload to target all users for each platform and also all platforms.
 
Android app iOS app web (Chrome Push) Windows app Across all platform
{
  "appId": "MAZW5N1IMMSH5H67C3T9KBHK",
  "campaignName": "Test Push", // Name of the campaign.
  "signature": "d7d28929ba474edf293b7c892efe22ec0e426ab1ba242b50c96f3126b9285385",
  "requestType": "push", // Type of request (push)
  "targetPlatform": [
    "ANDROID"
  ],
  "targetAudience": "All Users",
  "payload": {
    "ANDROID": { // Android Payload, detailed is described above
      "message": "Android Message",
      "title": "Android Message Title",
      "Summary": "Android Summary",
      "richContent": [
        {
          "type": "image",
          "value": "https://images.iimg.in/c"
        },
        {
          "type": "coupon",
          "value": "free"
        },
        {
          "type": "sound",
          "value": "tring"
        }
      ],
      "defaultAction": {
        "type": "richlanding",
        "value": "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8 "
      },
      "additionalActions": [
        {
          "type": "call",
          "value": "12345678",
          "name": "Call button",
          "iconURL": "abc"
        },
        {
          "type": "copy",
          "value": "12345678",
          "name": "Copy button",
          "iconURL": "abc"
        }
      ]
    }
  },
  "campaignDelivery": { 
    "type": "soon", //values can be - soon/later/periodic; if later/periodic, please provide respective values as well.
  },
  "conversionGoals": [
    {
      "name": "amount 1",
      "eventName": "AddedTocart",
      "attrs": {
        "filter": "is between",
        "name": "amount",
        "value": "10,100",
        "type": "numeric"
      }
    }
  ],
  "advancedSettings": {
    "ttl": {
      "ANDROID": 12
    },
    "ignoreFC": "false",
    "sendAtHighPriority": "true",
    "inboxExpiry": 360  //in hours

  }
}

 

Example 3

This example shows different payloads to target different segments of users.

Target Single User Target Custom Segment Target All Users
{
  "appId": "MAZW5N1IMMSH5H67C3T9KBHK",
  "campaignName": "Test Push", // Name of the campaign.
  "signature": "d7d28929ba474edf293b7c892efe22ec0e426ab1ba242b50c96f3126b9285385",
  "requestType": "push", // Type of request (push)
  "targetPlatform": [
    "ANDROID"
  ],
  "targetAudience": "User",
  "targetUserAttributes":{
    "attribute": "USER_ATTRIBUTE_USER_EMAIL",
    "comparisonParameter": "is",
    "attributeValue": "abc@example.com"
  },
  "payload": {
    "ANDROID": { // Android Payload, detailed is described above
      "message": "Android Message",
      "title": "Android Message Title",
      "Summary": "Android Summary",
      "richContent": [
        {
          "type": "image",
          "value": "https://images.iimg.in/c"
        },
        {
          "type": "coupon",
          "value": "free"
        },
        {
          "type": "sound",
          "value": "tring"
        }
      ],
      "defaultAction": {
        "type": "richlanding",
        "value": "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8 "
      },
      "additionalActions": [
        {
          "type": "call",
          "value": "12345678",
          "name": "Call button",
          "iconURL": "abc"
        },
        {
          "type": "copy",
          "value": "12345678",
          "name": "Copy button",
          "iconURL": "abc"
        }
      ]
    }
  },
  "campaignDelivery": { 
    "type": "soon", //values can be - soon/later/periodic; if later/periodic, please provide respective values as well.
  },
  "conversionGoals": [
    {
      "name": "amount 1",
      "eventName": "AddedTocart",
      "attrs": {
        "filter": "is between",
        "name": "amount",
        "value": "10,100",
        "type": "numeric"
      }
    }
  ],
  "advancedSettings": {
    "ttl": {
      "ANDROID": 12
    },
    "ignoreFC": "false",
    "sendAtHighPriority": "true",
    "inboxExpiry": 360  //in hours

  }
}

 

Example 4

This payload describes the sample for the push API response payload.

// sample success push respons payload
{
 "status": "Success",// shows valid request and accepted for processing
 "responseId": "cd13199a-0f70-4bf2-9c54-99879eefae76",
 "requestId": "",
 "cid": "581e08281069b855c03576d2"
}

// sample failure push response payload
{
 "status": "Fail", // shows invalid request
 "Error_Message": "Campaign Name not found", // reason of failure
 "responseId": "5612064a-24fa-4e8c-9e8a-c1c4221fe0ea",
 "requestId": "", 
}
Was this article helpful?
0 out of 1 found this helpful