Create Filter Segment
This API creates a new segment based on a set of filter conditions.
Generate Request from Dashboard
To simplify payload generation, MoEngage provides a tool in the dashboard where you can configure filters and export the payload.- Log in to the MoEngage dashboard.
- Click Test & Debug at the lower left in the side panel.
- Click Segment Payload.
- Specify the segment name and configure the required filters.
- Click Generate Payload.
Rate Limit
The rate limit is 50 requests/minute, 200 requests/hour, and 1000 requests/day.Payload Reference
Top-Level Structure
Every segment request is a tree of filters underincluded_filters and an optional excluded_filters root.
filter_operator at every level accepts "and" or "or". Groups can nest to arbitrary depth using nested_filters.
Filter Types
User Property Filter (filter_type: "user_attributes")
Required Fields
project_name. See Portfolio Workspaces under the User Behavior filter for the values it takes.
Supported Data Types
containsSpaces or is_empty operator at the payload level. Send the equivalent operator and value instead:
negate: true to express “does not contain spaces” or “is not empty”.
value shape by operator:
- Array:
in(string, double, array types);containsInTheFollowing,startsWithInTheFollowing,endsWithInTheFollowing(string);contains,startsWith,endsWith(array_string);in(datetime with time/day/month extract types) - Scalar:
is(bool, datetime, and the string/array_string cases in the table above),on,before,after,lessThan,greaterThan,inTheLast,inTheNext - Absent:
exists,today
exists cleans up: When operator is exists, value, value1, and value_type are removed from the payload.
Datetime value_type and extract_type
Set value_type to:
"absolute"—valueis an ISO 8601 date string, for example"2024-01-15T00:00:00.000Z""relative_past"—valueis an integer number of days/hours/months ago"relative_future"—valueis an integer number of days/hours/months in the future (used with theafterandinTheNextoperators)
extract_type to filter on a specific part of the date. Omit it to match on the full date:
"time_of_the_day"— hour (0–23)"day_of_the_week"— weekday (0–6)"day_of_the_month"— day (1–31)"month_of_the_year"— month (1–12)"date_month_of_the_year"— month and day as anMM-DDstring, for example"06-15"
Cross-Attribute Comparison (Dynamic Values)
To compare a user attribute against another user attribute rather than a literal, setis_dynamic_value: true, set dynamic_attribute_type to the base type of the referenced attribute, and use a template string in value:
dynamic_attribute_type uses the base element type: array_string → "string", array_double → "double". For datetime, value_type is forced to "absolute".
Cross-attribute comparison is not available for:
objectandarray_objectattributes.doubleandarray_doubleattributes whenoperatorisbetween.
User Behavior Filter (filter_type: "actions")
Required Fields
Execution (Frequency)
executed: false, execution is { "type": "exactly", "count": 0 }.
Primary Time Range
primary_time_range stores five keys: type, value, value1 (only for between), value_type, and period_unit. The payload accepts five type values:
period_unit accepts hours, days, weeks, or months, and applies to inTheLast.
The dashboard also offers calendar windows such as Today and This week. These are not payload type values — each maps onto type: "on" with a specific value and period_unit:
value → YYYY-MM-DDT00:00:00.000Z; value1 → YYYY-MM-DDT23:59:59.999Z. For between, value1 must be greater than value.
days (and days1) instead of value and period_unit. A response for one of those segments returns that form. Send value, value_type, and period_unit when you create or update a segment through the API.Event Attribute Sub-Filters
Use theattributes block to narrow which event occurrences count — for example, a purchase event where product_category is "electronics".
Inner filters follow the same shape as User Property filters, with two differences:
filter_typeis"action_attributes"instead of"user_attributes".categoryis"default".
filter_type when it echoes these filters back in a response, so send it on the request even though a GET on the segment will not show it.
Inner filters start directly from filter_operator and filters — do not add included_filters or excluded_filters inside the attributes block.
Aggregation (sum / avg / min / max / median)
Addaggregation_attributes to compare an aggregate of a numeric event attribute against a threshold. The block holds exactly one filter.
Aggregation is only available when executed: true, execution.type is not firstTime or lastTime, and primary_time_range.type is not before or after.
comparator is change or percentageChange, add base_time_range to define the window to compare against:
Portfolio (Multi-Project) Workspaces
In workspaces with more than one project, addproject_name to scope a filter to a specific project. Both User Behavior and User Property filters accept the key. Omit it in single-project workspaces.
Set project_name to the name of the project you want to scope to. "moe_portfolio" is one of the available values and targets all projects.
User Affinity Filter (filter_type: "psychographic_event")
Targets users based on behavioral affinity over an event. primary_time_range and psychographic_attributes are required.
Psychographic attribute filters support only the string and double data types, use category values such as "Event Attributes", and carry no filter_type key. The primary_time_range object also uses a different shape from User Behavior filters: relative windows use days (and days1) instead of value/value1, and absolute windows use from and to ISO 8601 dates, along with type and value_type.
Time-Based Affinity Filters
Four affinity filters target the time at which the event happens rather than an event attribute. Each uses the attribute namemoe_user_datetime, category "Time Attributes", data_type "double", and an extract_type:
value follows the operator: a scalar for is, an array for in, and value plus value1 for between.
Custom Segment Filter (filter_type: "custom_segments")
References a saved segment by ID. The backend resolves the segment by id; name is a display label only.
Nested Filters (filter_type: "nested_filters")
Use nested_filters inside included_filters or excluded_filters to create complex boolean logic (for example, (A AND B) OR (C AND D)). Groups can nest to arbitrary depth.
Authorizations
Authentication is done via Basic Auth. This requires a base64-encoded string of your credentials in the format 'username:password'.
- Username: Use your MoEngage workspace ID (also known as the App ID). You can find it in the MoEngage dashboard at Settings > Account > APIs > Workspace ID (earlier app id).
- Password: Use your API Key, which you can find within the Data tile.
For more information on authentication and getting your credentials, refer here.
Headers
This is the Workspace ID of your MoEngage account that must be passed with the request. You can find it in the MoEngage dashboard at Settings > Account > APIs > Workspace ID (earlier app id).
You can send MOE-DBNAME with your database name instead of this header. The request must include one of the two.
Your MoEngage database name. Send this as an alternative to MOE-APPKEY when you identify the
workspace by database name. Omit it when MOE-APPKEY is already present.
Body
The filter definition for the new segment.
Request schema for creating a filter-based segment.
A unique name for the segment.
The filter criteria for users to include in the segment. Users matching these filters are added to the segment.
Optional. The filter criteria for users to exclude. Users matching these filters are removed from the
included set even if they satisfy included_filters.
Response
Segment created successfully. Returns the newly created segment details including its unique ID, filter definition, and metadata.