Skip to main content
POST
This API endpoint does not currently support Team-level scoping. All segments generated using this call will be assigned to the Default Team automatically.

Generate Request from Dashboard

To simplify payload generation, MoEngage provides a tool in the dashboard where you can configure filters and export the payload.
  1. Log in to the MoEngage dashboard.
  2. Click Test & Debug at the lower left in the side panel.
  3. Click Segment Payload.
  4. Specify the segment name and configure the required filters.
  5. 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 under included_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

In portfolio (multi-project) workspaces, User Property filters also accept project_name. See Portfolio Workspaces under the User Behavior filter for the values it takes.

Supported Data Types

“Contains spaces” and “is empty”: the dashboard shows these as operators, but there is no containsSpaces or is_empty operator at the payload level. Send the equivalent operator and value instead: Negate either one with 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"value is an ISO 8601 date string, for example "2024-01-15T00:00:00.000Z"
  • "relative_past"value is an integer number of days/hours/months ago
  • "relative_future"value is an integer number of days/hours/months in the future (used with the after and inTheNext operators)
Set 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 an MM-DD string, for example "06-15"

Cross-Attribute Comparison (Dynamic Values)

To compare a user attribute against another user attribute rather than a literal, set is_dynamic_value: true, set dynamic_attribute_type to the base type of the referenced attribute, and use a template string in value:
Segment creation supports comparing a user attribute against another user attribute only. Comparing against an event attribute or a business event attribute is available in campaign filters, not when creating a segment.
For array types, 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:
  • object and array_object attributes.
  • double and array_double attributes when operator is between.

User Behavior Filter (filter_type: "actions")

Required Fields

The three object fields use these key names:

Execution (Frequency)

When 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: Absolute date formatting: valueYYYY-MM-DDT00:00:00.000Z; value1YYYY-MM-DDT23:59:59.999Z. For between, value1 must be greater than value.
Segments built in the dashboard store relative windows as 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 the attributes 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_type is "action_attributes" instead of "user_attributes".
  • category is "default".
The API omits 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)

Add aggregation_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.
Comparing against an earlier window. When 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, add project_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 name moe_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

Authorization
string
header
required

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

MOE-APPKEY
string
required

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.

MOE-DBNAME
string

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

application/json

The filter definition for the new segment.

Request schema for creating a filter-based segment.

name
string
required

A unique name for the segment.

included_filters
object
required

The filter criteria for users to include in the segment. Users matching these filters are added to the segment.

excluded_filters
object

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.

Response schema for filter segment operations (create/update).

data
object

Information about the segment.

response_id
string

A unique identifier for this API response.

type
string

The type of resource referenced in the response.

Example:

"custom_segment"