Create segment
Programmatically create segments in your OneSignal app using flexible filters and targeting rules.
Documentation Index
Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Use this API to create new Segments programmatically. These segments are then accessible in the OneSignal Dashboard and usable in messages, Journeys, and in-app messaging campaigns.How to use this API
This endpoint allows your backend to define audience segments by passing in a combination of filters and logical operators like"AND" and "OR", mirroring the segmentation capabilities of the OneSignal Dashboard.
Name the segment
The name of the segment as it shows in the OneSignal dashboard and accessible via theincluded_segments and excluded_segments targeting parameters.
Describe the segment
Optionally include adescription (max 255 characters) to record the segment’s purpose. The description is returned by the View segments and View segment APIs.
Define the filters
Available filters:
- operator
- tag
- last_session
- first_session
- session_count
- session_time
- language
- app_version
- location
- country
operator
Description
Allows you to combine or separate properties. Filters combined with an "AND" have higher priority than "OR" filters.
"AND"= the 2+ connected filters must be satisfied for the recipient to be included. Filter entries use this by default and its not required to be included."OR"= the 2 filters separated by the"OR"operator are mutually exclusive. The recipients only need to satisfy the conditions on either side of the"OR"operator.
tag
Description
Target based on custom user Tags.
relation=">","<","=","!=","exists","not_exists","time_elapsed_gt", (time elapsed greater than) and"time_elapsed_lt"(time elapsed less than)time_elapsed_gt/ltfields correspond to Time Operators and require a paid plan.
key= Tag key to compare.value= Tag value to compare. Not required for"exists"or"not_exists".
last_session
Description
Time since the Subscription last used the app (in hours_ago).
-
relation=">"or"<" -
hours_ago= number of hours before or after the user’s last session. Example:"1.1"
first_session
Description
Time since the User first used the app or was created within OneSignal (in hours_ago).
-
relation=">"or"<" -
hours_ago= number of hours before or after the user’s first session. Example:"1.1"
session_count
Description
Total number of sessions by the Subscription.
-
relation=">","<","="or"!=" -
value= number of sessions. Example:"1"
session_time
Description
Total time the Subscription has spent in the app, in seconds.
-
relation=">"or"<" -
value= time in seconds the user has been in your app. Example: 1 day is"86400"seconds.
language
Description
User’s language code (e.g., “en”). See Multi-Language Messaging for details and supported language codes.
-
relation="=","!=","in_array", or"not_in_array" -
value= 2 character language code. Example:"en". For"in_array"and"not_in_array", the value should be a comma-separated list of values.
app_version
Description
App version set on the Subscription.
-
relation=">","<","="or"!=" -
value= app version. Example:"1.0.0"
location
Description
Target by GPS coordinates and radius. Location tracking must be turned on and accepted by the user. See Location-Triggered Notifications for details.
-
radius= in meters -
lat= latitude -
long= longitude
country
Description
Country code of your Users. Uses ISO 3166-1 Alpha-2 format (two-letter country code).
-
relation="=","!=","in_array", or"not_in_array" -
value= Two-letter country code in uppercase. Example:"US","GB","CA". For"in_array"and"not_in_array", the value should be a comma-separated list of values.
Path Parameters
Your OneSignal App ID in UUID v4 format. See Keys & IDs.
Body
An internal name you set to help organize and track Segments. Maximum 128 characters.
Filters define the segment based on user properties like tags, activity, or location using flexible AND/OR logic. Limited to 200 total entries, including fields and OR operators. See Sending messages with the OneSignal API.
1 - 200 elementsRequired. The fitler object.
- Filter
- Operator
UUID of the segment. If left empty, it will be assigned automatically.
Optional human-readable description for the segment. Maximum 255 characters.
255