File Segment API

If you need to create segments by importing a large number of users, we recommend utilising the File segment API. This API allows you to easily generate a file segment by initiating a call to the file segment API endpoint. To proceed, you will need to compile a CSV file containing the relevant users (ensuring that the users are already present in MoEngage). It is essential to provide the public path of the file, which allows for downloading and identification of users in order to successfully create the file segment.

Use the Custom File Segment API to:

Request Headerslink

Request headers are applicable to create, update, archive, or unarchive the custom segment.

HeaderTypeDescription
Content-Type{"Content-Type": "application/json"}Set the Content-Type header to application/JSON for using the Data API.
DatabaseMOE-DBNAMESet the database from which the data is available.
Authorization{"Authorization": "Basic bmF2ZWVua3VtYXI6bW9lbmdhZ2U="}Basic authentication is used for access control.
info

Info

The Content Types that MoEngage accepts for File Segments are as follows:

  • "text/csv"
  • "application/csv"
  • "application/vnd.ms-excel"
  • "text/plain"
  • "application/octet-stream"

Any other Content Types besides the ones listed above will be rejected.

Authenticationlink

Authentication applies to create, update, archive, or unarchive APIs.

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 App 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.
Revamped Settings Old Settings
API_Authentication_RevampedUI.png

Authentication is performed using a client like Postman as follows:

df440da-f0c37fd-postman_new_sample.png

 

If your file is private, you should whitelist these IPs to provide access only to MoEngage for the file.
DC-1 (US) - 184.72.243.80
DC-2 (EU) - 18.195.110.23
DC-3 (AP) - 3.6.251.95

Check the data center and API endpoint mapping page here.

Response Codeslink

HTTP Status CodeResponse Reason
200 - OKEverything worked as expected.
202 - AcceptedRequest accepted for the required operation.
400 - Bad RequestRequest not accepted due to missing a required parameter.
The reason is passed in the description field.
401 - UnauthorizedSignature is not valid.
404 - Entity not foundThe custom segment mentioned in the request does not exist.
409 - ConflictThe request conflicts with another request.
429 - Too Many RequestsThe number of requests or the rate of requests exceeds the allowed limit.
500, 502, 503, 504 - Server ErrorsSomething went wrong on MoEngage.

Limitslink

info

Note

The limit of 1000 custom file segments is calculated only for the file segments that are active. Most of our customers utilize only 30-40% of this limit at any given point.

Rate Limit NameRate Limit
total active segmentThe limit of the total number of active custom segments at a time for a client is 1000.
file_segment ops per hourThe total number of file segment operations(which are create-segment/add-users/remove-users) per hour per client allowed is 10.
file_segment ops per dayThe total number of file segment operations(which are create-segment/add-users/remove-users) per day per client allowed is 100.
file_segment users per dayThe total number of users that can be uploaded via the File segment is limited to 2 million per day.
file_size_limitThe size of the file from which the segment is created/updated. For each request, the file size limit is 150 MB.
info

Note

  • Breaching the limits will reject the request
  • Per hour and per day limits will consider the calculation based on the last hour and last 24 hrs respectively.

Create File Segmentlink

API Endpointlink

URL
content_copy Copy Code
task_altCode Copied
POST https://api-0X.moengage.com/v2/custom-segments/file-segment

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 Bodylink

ParameterMandatoryDescription
nameYesThe name of the custom segment. The name should be unique across all segments.
attribute_nameYesName of the user attribute on which the segment is created.
For registered users, use ID (to indicate customer id) or any other unique attribute which uniquely identifies the user. For example, for Anonymous (not registered) users use email, mobile number, or any other identifier as the anonymous user identifier.
attribute_typeYesThe type is string or double based on the type of attribute_name. For double attribute_type, the attribute values should be within 64-bit signed numeric values, that is [-9223372036854775808, 9223372036854775807]
file_urlYesCSV file from URL should be downloadable without authorization.
expiry_timeYesSegment expiry time in days.
 - All existing users are dropped from the created custom segment after the expiry time.
 - The custom segment is archived after expiry time.
callback_urlNoCallback URL to receive the result of segment creation.
emailsNoList of email ids to receive segment creation response.

Use callback, emails, or both for better visibility and end-to-end integration capability.

info

Note

  • The attribute names should be separated by new lines. 
  • CSV should be a single column. CSV size should be less than 150MB.
  • Values should not end with a comma (,) For example, values in a row should be abcd and not abcd,
  • Values should not have duplicate, special characters. For string values use abcd and not "abcd". String value can not be a#bc.
  • File should not have empty rows or empty columns.
  • A user attribute value must uniquely identify a single user. If an attribute value identifies multiple users (e.g. a city attribute with the value 'London' may have many users) these multiple users may get mapped to a single attribute, become part of the segment, and may block other users from being included in the segment.
    For example, if you upload 5 emails and the first email matches with 3 users, the rest 4 emails match with one user each. In this case, the system will randomly pick 5 users to be added to the file segment. The system does this processing in batches of 2000.
  • Sample File Link

Responselink

Status CodeRequest StateDescriptionResponse Body
HTTP 202SuccessFile-segment creation request accepted.{ "message": "File-segment creation request accepted", "success": true, "cs_name": <custom_segment_unique_name> }
HTTP 401FailureAuthentication or Authorization Failure. Invalid key or Secretor Database Name or Authorization Header.{ "title": "Authentication required", "description": <message> }
HTTP 409FailureFile-segment creation attempt with duplicate name.{ "title": "Resource not created", "description": "Name already exists : <custom_segment_name>" }
HTTP 429FailureThe number of requests or the rate of requests exceeds the allowed limit.{ "title": "Too Many Requests", "description": <appropriate message> }
HTTP 5xxFailureServer issue{ "title": "Internal Server Error", ... }

Examplelink

HTTP
content_copy Copy Code
task_altCode Copied
POST https://api-0X.moengage.com/v2/custom-segments/file-segment
Body
{
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs.csv",
"callback_url": "http://localhost:5000",
"emails": ["abc@gmail.com", "xyz@wrx.com"],
"expiry_time": 30
}

Callback Sample Body

Success Failure-1 Failure-2 Failure-3
content_copy Copy Code
task_altCode Copied
{
"db_name": "test_db",
"segment_name": "test_segment_name",
"request_id": "d5a263c4ef1198ae3d8496c0460f570f",
"values_found":80 ,
"values_processed": 70,
"user_count": 60,
"status": 201
}
info

Note - Segment Processing & Availability

As soon as the request is received at the MoEngage system, MoEngage creates a custom segment with zero users. After this, the file is processed and users are added to the custom segment. If the created custom segment is queried in between the file processing, it will show zero or partial user count.

 

Add users to file segmentlink

API Endpointlink

URL
content_copy Copy Code
task_altCode Copied
PUT https://api-0X.moengage.com/v2/custom-segments/file-segment/add-users

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 Headerslink

ParameterMandatoryDescription
nameYesName of the custom segment to which the users are added.
attribute_nameYesName of the user attribute on which the segment is added.
For registered users, use ID (to indicate customer id) or any other unique attribute which uniquely identifies the user. For example, for Anonymous (not registered) users use email, mobile number, or any other identifier as the anonymous user identifier.
attribute_typeYesThe type is string or double based on type of attribute_name. For double attribute_type, the attribute values should be within 64-bit signed numeric values, that is [-9223372036854775808, 9223372036854775807]
file_urlYesURL of the CSV file.
- The attribute names should be separated by new lines.
- CSV size should be less than 150MB.
- CSV should be downloadable without authorization.
callback_urlNoCallback URL to receive the result of updated segment.
emailsNoList of email ids to receive segment response.

Use callback, emails, or both for better visibility and end-to-end integration capability.

Responselink

Status CodeRequest StateDescriptionResponse Body
HTTP 202SuccessFile-segment creation request accepted.{ "message": "File-segment user-add request accepted", "success": true, "cs_name": <custom_segment_unique_name> }
HTTP 400FailureInvalid file-segment request(invalid payload format).{ "title": "Invalid Request", "description": <message> }
HTTP 401FailureAuthentication or Authorization Failure. Invalid key or Secretor Database Name or Authorization Header.{ "title": "Authentication required", "description": <message> }
HTTP 404FailureThe custom-segment name used in the request does not exist.{ "title": "Entity Not Found", "description": "Custom segment not found with the given name: <custom_segment_unique_name>" }
HTTP 429FailureThe number of requests or the rate of requests exceeds the allowed limit.{ "title": "Too Many Requests", "description": <appropriate message> }
HTTP 5xxFailureServer issue{ "title": "Internal Server Error", ... }

Examplelink

HTTP
content_copy Copy Code
task_altCode Copied
PUT https://api-0X.moengage.com/v2/custom-segments/file-segment/add-users
Body
{
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs.csv",
"callback_url": "http://localhost:5000",
"emails": ["abc@gmail.com", "xyz@wrx.com"]
}

Remove users from File Segmentlink

API Endpointlink

URL
content_copy Copy Code
task_altCode Copied
PUT https://api-0X.moengage.com/v2/custom-segments/file-segment/remove-users

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 Bodylink

ParameterMandatoryDescription
nameYesName of the custom segment from which the users are removed.
attribute_nameYesName of the user attribute on which the segment is removed.
For registered users, use ID (to indicate customer id) or any other unique attribute which uniquely identifies the user. For example, for Anonymous (not registered) users use email, mobile number, or any other identifier as the anonymous user identifier.
attribute_typeYesThe type is string or double based on type of attribute_name. For double attribute_type, the attribute values should be within 64-bit signed numeric values, that is [-9223372036854775808, 9223372036854775807]
file_urlYesURL of the CSV file.
- The attribute names should be separated by new lines.
- CSV size should be less than 150MB.
- CSV should be downloadable without authorization.
callback_urlNoCallback URL to receive the result of segment deletion.
emailsNoList of email ids to receive segment deletion response.

Use callback, emails, or both for better visibility and end-to-end integration capability.

Responselink

Status CodeRequest StateDescriptionResponse Body
HTTP 202SuccessFile-segment creation request accepted.{ "message": "File-segment user-remove request accepted", "success": true, "cs_name": <custom_segment_unique_name> }
HTTP 400FailureInvalid file-segment request(invalid payload format).{ "title": "Invalid Request", "description": <message> }
HTTP 401FailureAuthentication or Authorization Failure. Invalid key or Secretor Database Name or Authorization Header.{ "title": "Authentication required", "description": <message> }
HTTP 404FailureThe custom-segment name used in the request does not exist.{ "title": "Entity Not Found", "description": "Custom segment not found with the given name: <custom_segment_unique_name>" }
HTTP 429FailureThe number of requests or the rate of requests exceeds the allowed limit.{ "title": "Too Many Requests", "description": <appropriate message> }
HTTP 5xxFailureServer issue{ "title": "Internal Server Error", ... }

Examplelink

HTTP
content_copy Copy Code
task_altCode Copied
PUT https://api-0X.moengage.com/v2/custom-segments/file-segment/remove-users
Body
{
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs.csv",
"callback_url": "http://localhost:5000",
"emails": ["abc@gmail.com", "xyz@wrx.com"]
}

Replace users from File Segmentlink

API Endpointlink

URL
content_copy Copy Code
task_altCode Copied
PUT https://api-0X.moengage.com/v2/custom-segments/file-segment/replace

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 Bodylink

ParameterMandatoryDescription
nameYesName of the custom segment from which all the previous users are removed and new users are added.
attribute_nameYesName of the user attribute on which the segment is removed.
For registered users, use ID (to indicate customer id) or any other unique attribute which uniquely identifies the user. For example, for Anonymous (not registered) users use email, mobile number, or any other identifier as the anonymous user identifier.
attribute_typeYesThe type is string or double based on type of attribute_name. For double attribute_type, the attribute values should be within 64-bit signed numeric values, that is [-9223372036854775808, 9223372036854775807]
file_urlYesURL of the CSV file.
- The attribute names should be separated by new lines.
- CSV size should be less than 150MB.
- CSV should be downloadable without authorization.
callback_urlNoCallback URL to receive the result of segment deletion.
emailsNoList of email ids to receive segment deletion response.

Use callback, emails, or both for better visibility and end-to-end integration capability.

Responselink

Status CodeRequest StateDescription 
HTTP 202SuccessReplace users request accepted.{
"message": "File-segment user-replace request accepted",
"success": true,
"cs_name": <custom_segment_unique_name>
}
HTTP 400FailureInvalid file-segment request(invalid payload format).{
"title": "Invalid Request",
"description":
}
HTTP 401FailureAuthentication or Authorization Failure. Invalid key or Secretor Database Name or Authorization Header{
"title": "Authentication required",
"description":
}
HTTP 404FailureThe custom-segment name used in the request does not exist.{
"title": "Entity Not Found",
"description": "Custom segment not found with the given name: <custom_segment_unique_name>"
}
HTTP 429FailureThe number of requests or the rate of requests exceeds the allowed limit.{
"title": "Too Many Requests",
"description": ,
"actual_count": ,
"limit":
}
HTTP 5XXFailureServer issue{
"title": "Internal Server Error",
...
}

Examplelink

HTTP
content_copy Copy Code
task_altCode Copied
PUT https://api-0X.moengage.com/v2/custom-segments/file-segment/replace
Body
{
"name": "custom_segment_unique_name",
"attribute_name": "unique_identifier",
"attribute_type": "string",
"file_url": "https://s3.amazonaws.com/Sample_GAIDs.csv",
"callback_url": "http://localhost:5000",
"emails": ["abc@gmail.com", "xyz@wrx.com"]
}
info

Note

  1. Replace users API drops all the existing user of the custom segment and add new users which are provided in the file URL.
  2. Only the newly added users are counted towards the daily file_segment_user limit.

Archive Custom Segmentlink

API Endpointlink

URL
content_copy Copy Code
task_altCode Copied
PATCH https://api-0X.moengage.com/v2/custom-segments/archive

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 Bodylink

ParameterMandatoryDescription
nameYesThe name of the custom segment to be archived.

Use callback, emails, or both for better visibility and end-to-end integration capability.

Responselink

Status CodeRequest StateDescriptionResponse Body
HTTP 202SuccessFile-segment creation request accepted.{ "message": "Successfully archived the custom segment", "success": true, "cs_name": <custom_segment_unique_name> }
HTTP 400FailureInvalid file-segment request(invalid payload format).{ "title": "Invalid Request", "description": <message> }
HTTP 401FailureAuthentication or Authorization Failure. Invalid key or Secretor Database Name or Authorization Header.{ "title": "Authentication required", "description": <message> }
HTTP 404FailureThe custom-segment name used in the request does not exist.{ "title": "Entity Not Found", "description": "Custom segment not found with the given name: <custom_segment_unique_name>" }
HTTP 5xxFailureServer issue{ "title": "Internal Server Error", ... }

Examplelink

HTTP
content_copy Copy Code
task_altCode Copied
PATCH https://api-0X.moengage.com/v2/custom-segments/archive
Body
{
"name": "custom_segment_unique_name"
}
info

Note

All the users from the archived file custom segment dropped after 30 days of archival.

UnArchive Custom Segmentlink

API Endpointlink

URL
content_copy Copy Code
task_altCode Copied
PATCH https://api-0X.moengage.com/v2/custom-segments/unarchive

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 Bodylink

ParameterMandatoryDescription
nameYesName of the custom segment not archived.

Use callback, emails, or both for better visibility and end-to-end integration capability.

Responselink

Status CodeRequest StateDescriptionResponse Body
HTTP 202SuccessFile-segment creation request accepted.{ "message": "Successfully unarchived the custom segment", "success": true, "cs_name": <custom_segment_unique_name> }
HTTP 400FailureInvalid file-segment request(invalid payload format).{ "title": "Invalid Request", "description": <message> }
HTTP 401FailureAuthentication or Authorization Failure. Invalid key or Secretor Database Name or Authorization Header.{ "title": "Authentication required", "description": <message> }
HTTP 404FailureThe custom-segment name used in the request does not exist.{ "title": "Entity Not Found", "description": "Custom segment not found with the given name: <custom_segment_unique_name>" }
HTTP 5xxFailureServer issue{ "title": "Internal Server Error", ... }

Examplelink

URL
content_copy Copy Code
task_altCode Copied
PATCH https://api-0X.moengage.com/v2/custom-segments/unarchive Body { "name": "custom_segment_unique_name" }

Previous

Next

Was this article helpful?
Yes No

How can we improve this article?