This Create Event API allows you to track the actions of a user.
warning |
Warning Send one of the following values for the platform: Android, iOS, or web. The platform value indicates the platform where the event originated. If the platform of origin is uncertain, send the value as unknown or do not send any value. Incorrect platform values can cause inconsistencies in platform-level campaigns, such as Push and In-App. |
info |
Information Current_time This field is necessary to specify the UTC time of the event. Acceptable formats for current_time include: ISO 8601 (For example, 2020-05-31T16:33:35Z)and Epoch time in seconds (For example, 1590404615). User_time This field lets the system identify the local system time for when the event happened. Acceptable formats for user_time are ISO 8601 (for example, 2020-05-31T16:33:35Z)and Epoch time in seconds (for example, 1590404615). User_timezone_offset This field is crucial for establishing the User_time or Current_time. This contains a numerical value between 54000 and 54000, representing the local timezone’s offset from UTC in seconds. MoEngage gets this information from the internal system in the sequence as follows:
Fields to be Provided MoEngage generates Current_time and User_time if they are not provided in the request. Use the following information and provide Current_time, User_time, and User_timezone_offset accordingly:
|
Example Payload
The following example provides tracking of numeric, boolean, and date-type event attributes.
Use the payload described, where the price is numeric, departure_date is a date type attribute, and premium_seat is a boolean attribute.
{
"type": "event",
"customer_id": "john@example.com",
"actions": [{
"action": "Flight Booked",
"attributes": {
"price": 3999,
"departure_date": "2019-05-21T03:47:35Z",
"premium_seat": true
},
"platform": "iOS",
"app_version": "1.2.3",
"current_time": 1433837969,
"user_timezone_offset": 19800
}
]
}
Response Codes
Success Response
{
"status": "success",
"message": "Your request has been accepted and will be processed soon."
}
Sample response if the actions are sent as an empty list:
{
"status": "fail",
"error": {
"attribute": "actions",
"message": "actions can not be empty Array",
"type": "MissingAttributeError",
"request_id": "izsZuQNw"
}
}
Sample response if the customer_id or user_alias is missing:
{
"status": "fail",
"error": {
"attribute": "customer_id",
"message": "customer_id is not found in the payload",
"type": "MissingAttributeError",
"request_id": "TtnwRNrU"
}
}
Sample response if the elements in actions are not in json format:
{
"status": "fail",
"error": {
"message": "Could not decode the request body. The JSON was incorrect or not encoded as UTF-8.",
"type": "Malformed JSON",
"request_id": "USkbHpIK"
}
}
Sample response if the action key is not present, or if it is not in string or unicode string format:
{
"status": "fail",
"error": {
"attribute": "action",
"message": "action is not found in the payload",
"type": "MissingAttributeError",
"request_id": "TgzuJhcj"
}
}
Sample response if the action key is not sent as a string:
{
"status": "fail",
"error": {
"message": "Could not decode the request body. The JSON was incorrect or not encoded as UTF-8.",
"type": "Malformed JSON",
"request_id": "USkbHpIK"
}
}
Sample response for authorization errors
{
"status": "fail",
"error": {
"message": "App Secret key mismatch. Please login to the dashboard to verify key",
"type": "Authentication required",
"request_id": "PVUDFisO"
}
}
Sample response for missing authentication header
{
"status": "fail",
"error": {
"message": "Authentication Header Required",
"type": "Authentication required",
"request_id": "PiSPjGQQ"
}
}
Sample response for when your account is blocked
{
"status": "fail",
"error": {
"message": "Your account is suspended. Please contact MoEngage team.",
"type": "BlockedClient",
"request_id": "ofHUEaEQ"
}
}
Sample response for when your account is suspended
{
"status": "fail",
"error": {
"message": "Your account is suspended. Please contact MoEngage team.",
"type": "Account Suspended",
"request_id": "gqJvCNYu"
}
}
Sample response for when 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"
}
}
Sample response for payloads exceeding the size limit
{
"status": "fail",
"error": {
"message": "Payload can not exceed 128KB",
"type": "Payload too large",
"request_id": "VFzDwhwt"
}
}
Sample response for unsupported media type
{
"status": "fail",
"error": {
"message": "Content type is not supported",
"type": "Unsupported media type",
"request_id": "SgBQfKJh"
}
}
Sample response for rate limit breach
{
"status": "fail",
"error": {
"message": "Rate limits for customers exceeded. Please Try After Some Time",
"type": "Rate Limits Exceeded",
"request_id": "onqucLYL"
}
}
Sample response for 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-01.moengage.com/v1/event/OAPQQ2AMD01MJZYZX1YPG?app_id=OAPQQ2AMD01MJZYZX1YPG' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic T0FQUVEyQU1EMDFNSMlRZWlgxWVBHOmxVcURvd2JqeGpleGdzR1ZVdlNA==' \
--data-raw '{
"type": "event",
"customer_id": "123",
"actions" : [
{
"action": "ProductAdded",
"attributes": {
"product" : "Accessories",
"color" : "Black",
"Brand" : "Adidas"
},
"platform" : "Android",
"app_version" : "1.2.3",
"user_time" : "1708939453396",
"current_time" : "1708939453396"
}
]
}'
Array Support
To pass an attribute in an array, use the following:
"Array_attributeName":["abc","123"],
The following is a sample cURL command for adding and removing elements in an array:
cURL
curl --location --request POST 'https://api-01.moengage.com/v1/event?app_id=VJ0GABESHMQA3L7WK3UR' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic VkoNNRVNITVFBM0w3V1YxRUVLM1VSOkZJd0N5dGZ0QWpZcl9tcVlldkVPVkFtbw==' \
--data-raw '{
"type": "event",
"customer_id": "John",
"actions" : [
{
"action": "product_selected",
"attributes": {
"product" : "Shirt",
"color" : "Green",
"moe_os_type":"Xbox",
"arraySupport":["abc","xyz"],
"Brand" : "Adidas"
},
"platform" : "TV",
"app_version" : "1.2.3",
"user_time" : "1710740192",
"current_time" : "1710740192"
}
]
}'
User Identity Resolution
If the User Identity Resolution feature is enabled in your workspace, include the workspace's configured identifiers within the user_identifiers parameter, where moe_mobile is one of the identifiers, as shown in the following:
cURL
curl --location --request POST 'https://api-01.moengage.com/v1/event?app_id=VJ0GABESHMQA3L7WK3UR' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic VkoNNRVNITVFBM0w3V1YxRUVLM1VSOkZJd0N5dGZ0QWpZcl9tcVlldkVPVkFtbw==' \
--data-raw '{
"type": "event",
"user_identifiers":{
"moe_mobile":"{{Mobile_Number}}"
},
"actions" : [
{
"action": "product_selected",
"attributes": {
"product" : "Shirt",
"color" : "Green",
"moe_os_type":"Xbox",
"arraySupport":["abc","xyz"],
"Brand" : "Adidas"
},
"platform" : "TV",
"app_version" : "1.2.3",
"user_time" : "1710740192",
"current_time" : "1710740192"
}
]
}'
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 to identify the events to a given user? What identifiers can I use?
Events in the payload need to be mapped to a given user who has executed the event. You must use the Customer ID to identify the events mapped to a customer. -
Can I send events for anonymous users?
No, anonymous users can be tracked using MoEngage SDKs. -
Can events be updated/modified?
Events in MoEngage are immutable. They can only be created; they cannot be updated or deleted.