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
Method: POST
https://api-{{0X}}.moengage.com/v1/customer/{{appId}}
The 'X' in the API Endpoint URL refers to the MoEngage Data Center (DC). MoEngage maintains different data centres for different clients. 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
|
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_WORKSPACEID_APIKEY=="}
The username and password details can be obtained from the MoEngage Dashboard. If you're using the API for the first time, follow these steps:
- 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 Data tile to copy the API key.
- Use these details to authenticate the API requests.
Request Parameters
| Key | Required | Data Type | Description |
|---|---|---|---|
|
app_id |
Yes |
String |
This is your MoEngage account's Workspace ID that has to be passed along with the request. You can find your Workspace ID at Settings > Account > APIs > Workspace ID. |
Request Headers
| Key | Required | Sample Values | Description |
|---|---|---|---|
|
Content-Type |
Yes |
{"Content-Type": "application/json"} |
Set the Content-Type header to application/json. |
|
Authorization |
Yes |
{"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.
{
"type": "customer",
"customer_id": "john@example.com",
"attributes": {
"name":"John",
"platforms" : [{"platform":"ANDROID", "active":"true"}]
}
}
Request Body Fields
| Key | Data Type | Required | 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. Not mandatory in Identity resolution enabled workspaces. |
| update_existing_only | Boolean/String | Optional |
This field should be passed in the request when only existing users in MoEngage should be updated. If this value is passed as true:
If this value is passed as false:
|
| attributes | JSON Object | Optional | A dictionary containing user attributes to add / update in the user profile. |
| platforms | List | Optional | 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 name | Display name | Data type | Description | Create through Track User API | Update through Track User API |
|---|---|---|---|---|---|
| publisher_name | Publisher Name | String | The name of the campaign publisher | yes | no |
| campaign_name | Campaign Name | String | The name of the campaign | yes | no |
| u_l_a | Last Seen | Time in epoch format | 1767092989259 | yes | no |
| cr_t | First Seen | Time in epoch format | 1767092989259 | yes | no |
| u_mb | Mobile Number (Standard) | String | 239697005661 | yes | yes |
| uid | ID | String | yTbVEc | yes | yes |
| u_bd | Birthday |
Information in ISO 8601 format. |
The birthdate of the user. For example: 2019-05-21T03:47:35Z | yes | yes |
| u_em | Email (Standard) | String | Email Address of the user. For example, john@example.com | yes | yes |
| u_n | Name | String | Full name of the user | yes | yes |
| u_ln | Last Name | String | Last name of the user | yes | yes |
| u_gd | Gender | String | The gender of the user | yes | yes |
| u_fn | First Name | String | First name of the user | yes | yes |
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.
{
"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
|
Reserved Keywords for User Attributes
Below is the list of keys that should not be used when tracking user attributes.
- USER_ATTRIBUTE_UNIQUE_ID
- USER_ATTRIBUTE_USER_EMAIL
- USER_ATTRIBUTE_USER_MOBILE
- USER_ATTRIBUTE_USER_NAME
- USER_ATTRIBUTE_USER_GENDER
- USER_ATTRIBUTE_USER_FIRST_NAME
- USER_ATTRIBUTE_USER_LAST_NAME
- USER_ATTRIBUTE_USER_BDAY
- USER_ATTRIBUTE_NOTIFICATION_PREF
- USER_ATTRIBUTE_OLD_ID
- MOE_TIME_FORMAT
- MOE_TIME_TIMEZONE
- USER_ATTRIBUTE_DND_START_TIME
- USER_ATTRIBUTE_DND_END_TIME
- MOE_GAID
- MOE_ISLATINSTALL
- statusUPDATE
- MOE_ISLAT
- user_idstatus
- user_id
- source
| info |
Note You can not use "moe_" as a prefix while naming events, event attributes, or user attributes. It is a system prefix and using it might result in periodic blacklisting without prior communication. |
Response Codes
| Status Code | Request State | Description |
|---|---|---|
|
200 |
Success |
This response is returned when the request is processed successfully. |
|
400 |
Bad Request |
This response is returned when the required parameters are missing from the request, attributes are not found, and incorrect values are passed. |
|
401 |
Unauthorized |
This response is returned when the request does not have valid authentication credentials. |
|
403 |
Account Blocked |
This response is returned when your MoEngage account is suspended or blocked. |
|
413 |
Payload Size Exceeded |
This response is returned when the payload size exceeds 128 KB. |
|
415 |
Unsupported Media Type |
This response is returned when the content type is not supported. |
|
429 |
Rate Limit Breach |
This response is returned when the number of requests has exceeded the rate limit. |
|
500 |
Internal Server Error |
This response is returned when the system runs into an unexpected error. |
Sample Response
Success Response
{
"status": "success",
"message": "Your request has been accepted and will be processed soon."
}
Customer ID is missing in the payload
{
"status": "fail",
"error": {
"attribute": "customer_id",
"message": "customer_id is not found in the payload",
"type": "MissingAttributeError",
"request_id": "ZbPXtKFL"
}
}
Customer ID is empty
{
"status": "fail",
"error": {
"attribute": "customer_id",
"message": "customer_id can not be empty Unicode String",
"type": "MissingAttributeError",
"request_id": "VgjtlxTu"
}
}
Array field error
{
"status": "fail",
"error": {
"attribute": "addValueToArrayField",
"message": "Cannot add and remove 'first_name' at the same time",
"type": "ArrayFieldError",
"request_id": "WPDAbugh"
}
}
Authorization errors
{
"status": "fail",
"error": {
"message": "App Secret key mismatch. Please login to the dashboard to verify key",
"type": "Authentication required",
"request_id": "PVUDFisO"
}
}
Missing authentication header
{
"status": "fail",
"error": {
"message": "Authentication Header Required",
"type": "Authentication required",
"request_id": "PiSPjGQQ"
}
}
Your account is blocked
{
"status": "fail",
"error": {
"message": "Your account is suspended. Please contact MoEngage team.",
"type": "BlockedClient",
"request_id": "ofHUEaEQ"
}
}
Your account is suspended
{
"status": "fail",
"error": {
"message": "Your account is suspended. Please contact MoEngage team.",
"type": "Account Suspended",
"request_id": "gqJvCNYu"
}
}
Your account is temporarily suspended
{
"status": "fail",
"error": {
"message": "Your account is temporarily suspended. Please contact MoEngage team.",
"type": "Account Temporarily Suspended",
"request_id": "ssSJjoyD"
}
}
Payloads exceeding the size limit
{
"status": "fail",
"error": {
"message": "Payload can not exceed 128KB",
"type": "Payload too large",
"request_id": "VFzDwhwt"
}
}
Unsupported media type
{
"status": "fail",
"error": {
"message": "Content type is not supported",
"type": "Unsupported media type",
"request_id": "SgBQfKJh"
}
}
Rate limit breach
{
"status": "fail",
"error": {
"message": "Rate limits for customers exceeded. Please Try After Some Time",
"type": "Rate Limits Exceeded",
"request_id": "onqucLYL"
}
}
Unknown errors
{
"status": "fail",
"error": {
"message": "An unexpected error was encountered while processing this request. Please contact MoEngage Team",
"type": "Server Error",
"request_id": "KovrwJiF"
}
}
Sample cURL Request
curl --location --request POST 'https://api-0X.moengage.com/v1/customer/{{appId}}?app_id={{appId}}' \
--header 'Content-Type: application/json' \
--header {"Authorization": "Basic Base64_ENCODED_APPKEY_APIKEY"} \
--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:
"Array_attributeName":["abc","123"],
The sample cURL for adding and removing elements in an array is:
curl --location --request POST 'https://api-0X.moengage.com/v1/customer/{{appId}}?app_id={{appId}}'\
--header 'Content-Type: application/json' \
--header {"Authorization": "Basic Base64_ENCODED_APPKEY_APIKEY"} \
--data-raw '{
"type" : "customer",
"customer_id": "123",
"attributes": {
"removeValueFromArrayField": {
},
"addValueToArrayField": {
"attribute1":["abc","def"],
"attribute2":["a"],
"attribute3":["123"]
},
"platforms" : [{"platform":"iOS", "active":"true"}]
}
}'
User Identity Resolution
If the User Identity Resolution feature is enabled in your workspace, the attribute parameters in the payload must contain at least one of the identifiers you have activated in your workspace based on which users in MoEngage will be created, updated, or merged.
In the following example, moe_mobile is one of the identifiers in the workspace and is passed in attributes:
{
"type": "customer",
"attributes": {"moe_mobile": "{{Mobile_Number}}",
"first_name": "John"
}
}
For more information, refer to User Identity Resolution.
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.