Track User

Overview

User API helps add or update users and user properties in MoEngage.

 

Use cases:

  • Create a new user
  • Create new user property
  • Update existing user properties of users

 

API Endpoint

URL
POST https://api-0X.moengage.com/v1/customer/<APP_ID>

The 'X' in the API Endpoint URL refers to the MoEngage Data Center (DC). MoEngage hosts each customer in a different DC. You can find your DC number (value of X) and replace the value of 'X' in the URL by referring to the DC and API endpoint mapping here.

info

Note

The APP_ID for your MoEngage account is available on the MoEngage Dashboard. We've revamped our settings UI; you can find the APP_ID in the following navigations in the revamped and old UIs:

    • Revamped UI: Settings -> Account -> APIs -> Workspace ID
    • Old UI: Settings -> App Settings -> Account Settings -> APP ID

 

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="}

The username and password details can be obtained from the MoEngage Dashboard. We've revamped the settings UI in the Dashboard. If you're using the API for the first time, follow these steps for the revamped and old UIs:

Revamped UI

  1. Navigate to Settings -> Account -> APIs.
  2. Click Generate Key in the Data tile in the API Keys section, and click Save.
  3. Use the Workspace ID as the username and the Data API Key as the password to generate the authentication header.

Old UI

  1. Navigate to Settings -> APIs -> DATA API Settings.
  2. Click Generate Key.
  3. Click Save on the Data APIs settings section. 
  4. Use the DATA API ID as the username and the DATA API KEY as the password to generate the authentication header.

Request Parameters

Key Mandatory/Optional Data String Description

app_id

Mandatory

String

This is your MoEngage account's Workspace ID that has to be passed along with the request. You can find your Workspace ID in the following navigation on the Dashboard:

Revamped UI: Settings > Account > APIs > Workspace ID

Old UI: Settings > API > General Settings > DATA API KEY

Request Headers

Key Mandatory/Optional Sample Values Description

Content-Type

Mandatory

{"Content-Type": "application/json"}

Set the Content-Type header to application/json.

Authorization

Mandatory

{"Authorization": "Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U=="}

This authentication parameter, used for access control, must be passed along with the request. To generate the authentication header, refer to Authentication.

X-Forwarded-For

Optional

Header Value Format: <IP Address>

The 'X-Forwarded-For' header is used to specify the IP address of the client that made the request. This header may be added by proxy servers or load balancers. The header value must contain the IP address of the original client that initiated the request. Multiple IP addresses may be specified in the header value, separated by commas.

Request Body

A sample request body is described for the user with the unique id john@example.com.

JSON
{
"type": "customer",
"customer_id": "john@example.com",
"attributes": {
    "name":"John",
    "platforms" : [{"platform":"ANDROID", "active":"true"}]
    }
}

Request Body Fields

Key Datatype Mandatory Field Description
type String Yes

This is used to identify the type of request. 

Allowed Value: customer

Example: "type": "customer"

Note: This field is case-sensitive. Follow the case as in the example when passing the value in the request.

customer_id String Yes The unique identifier is used to identify/create a user in MoEngage. Please refer to this section for more information on customer_id.
update_existing_only Boolean/String No

This field should be passed in the request when only existing users in MoEngage should be updated.

If this value is passed as true:

  1. Only those users for whom the customer_id from the request payload matches the customer identifier in MoEngage will be updated.
  2. In case of new users (customer_id in the payload does not match any of the existing customer ids in your MoEngage account), they will not be created.

If this value is passed as false:

  1. The user attributes will be updated with the values present in the payload for existing customers.
  2. In case of new users (customer_id in the payload does not match any of the existing customer ids in your MoEngage account), a new customer will be created in the system with the details specified in the payload.
attributes JSON Object No A dictionary containing user attributes to add / update in the user profile.
platforms List No List of dictionaries with the associated platforms out of ANDROID, iOS, and web and their status.

Standard User Attributes

The following standard user attributes are tracked for User API in MoEngage.

info

Information

In the MoEngage platform, the standard attributes are identified when an attribute has (standard) marked right next to it - for example, email(standard).

Key Attribute Name on Dashboard Datatype Description
name Name String Full name of the user.
first_name First Name String First name of the user.
last_name Last Name String Last name of the user.
email Email (Standard) String Email Address of the user. For example, john@example.com
age Age Numeric Age of the user
gender Gender String Gender of the user
mobile Mobile Number (Standard) String Mobile Number of the user. For example, 918888444411
moe_geo_location Location

Array of [lat,lng] in double in the format {"lat": 12.11, "lon": 123.122}

A sample value would be the location of the user. For example: {"lat": 12.11, "lon": 123.122}
source Publisher Name String This is the Publisher Name of Install. For example, Google Ads
cr_t First Seen Date The time when the user was created.
Information in ISO 8601 format.
For example: 2019-05-21T03:47:35Z
u_l_a Last Seen Date Last Seen Time of the user.
Information in ISO 8601 format.
For example 2020-05-01T03:52:35Z
transactions Number of Conversions Numeric A total number of conversions made by the user in a lifetime.
revenue LTV Numeric Life Time Value of the user.
u_bd Birthday Date

The birthdate of the user.

Information in ISO 8601 format.
For example: 2019-05-21T03:47:35Z

moe_unsubscribe Unsubscribe Boolean Email Unsubscribe Attribute.
Emails are not sent to the user when the set value is true.
platforms Not visible on the dashboard. List Value is based on the active platforms of the user.
For example: [{"platform":"ANDROID", "active":"true"},{"platform":"IOS", "active":"true"}]
moe_hard_bounce Hard Bounce Boolean

Email Hard Bounce Attribute.

The emails are not sent to the user when the set value is true.

moe_spam Spam Boolean

Email Spam Attribute.

The emails are not sent to the user when the set value is true.

For other attributes that are not part of the list, use the key-value pairs that you intend to use.

Example Payload

For example, to track custom attributes of different data types like string, numeric, boolean, and date, pass the following payload where points are a number, expiry_date is a date type attribute, and super_user is a boolean attribute.

JSON
{
    "type" : "customer",
    "customer_id": "john@example.com",
    "update_existing_only":"true",
    "attributes": {
        "points":20,
        "expiry_date":"2020-05-31T03:47:35Z",
        "super_user":true,
        "user_persona":"browsers",
        "platforms" : [{"platform":"ANDROID","active":"true"}]
    }
}
info

Note

  • "id", "_id", and "" keywords are blocked and not to be used as user attribute names.
  • You can not use "moe_" as a prefix while naming user attributes. It is a system prefix and using it might result in periodic blacklisting without prior communication.

 

Response Codes

200 400 401 403 413 415 429 500
Success Response
{ "status": "success", "message": "Your request has been accepted and will be processed soon." }

Sample cURL Request

cURL
curl --location --request POST 'https://api-01.moengage.com/v1/customer/VJ0GSMESHMQA3L7WV1EEK3app_id=VJ0GSMESHMQA3L7EEK3UR' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic VkowQNRVNITVFBM0w3V1YxR1VSOkZJd0NGZ0QWpZcl9tcVlldkVPFtbw==' \
--data-raw '{
"type": "customer",
"customer_id": "123",
"attributes": {
"name": "JohnDoe",
"first_name": "John",
"platforms": [
{
"platform":"iOS",
"active": "true"
}
]
}
}'

 

Array Support

If you want to pass an attribute in an array, the appropriate syntax for that is:

cURL
"Array_attributeName":["abc","123"],

The sample cURL for adding and removing elements in an array is:

cURL

curl --location --request POST 'https://api-01.moengage.com/v1/customer/VJ0GSMESHMQA3L7WEK3UR?app_id=VJ0GSMESHMQA3L7WEK3UR' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic VkowR1NNRVNITVFBM0w3V1YxRUVLM1VSOkZJd0N5dGZ0QWpZcl9tcVlldkVPVkFtw==' \
--data-raw '{
"type" : "customer",
"customer_id": "123",
    "attributes": {
        
        "removeValueFromArrayField": {
            
            },

        "addValueToArrayField": {
                "attribute1":["abc","def"],
                "attribute2":["a"],
                "attribute3":["123"]
            },
            
        "platforms" : [{"platform":"iOS", "active":"true"}]
    }
}'

    

Postman Collections

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

FAQs

  • How do we reduce the 5xx errors because of too many requests per second/minute?
    Please attempt exponential backoff of requests to ensure there is no data loss due to 5xx errors.

  • How do I know if my user data has been ingested into MoEngage?
    Getting a 200 status code as a response from MoEngage only indicates that the users in your API payload have been accepted for processing. It does not ensure that the users sent to MoEngage have been successfully ingested. 
    Although, this happens very rarely and you can search for newly ingested users in:
    Segment > Create Segment > Search for users using their IDs

  • Can I use this API to also export users?
    Please use the Get User API to export the users.

  • Can I use this API to delete users from MoEngage?
    Please use the Delete User API to delete existing users in MoEngage.

Previous

Next

Was this article helpful?
4 out of 15 found this helpful

How can we improve this article?