This page describes the fields for the segment create API endpoint

This guide describes the available options for conditions for the API create segment endpoint.

For more information on segments review our segmentation guide.

Conditions

Conditions have the following basic format:

{
    "title": "Test",
    "conditions":  {
        "operator": "AND",
        "0": {
            "operator": "AND",
            "0": [ condition1 ],
            "1": [ condition2 ], 
             .....
        } .....
    }
}

An operator is used between groups of conditions. Options are AND or OR. Groups of conditions are label from 0-n, ie. "operator": "AND", "0": {group 1}, "operator": "AND", "1": {group 2}, ......

An operator is also used for at the start of a group of conditions. All conditions are combined using this operator.

An individual condition is made up of a mix of possible components:

  • keyword
    • comparator
    • value
  • option
    • comparator
    • value
  • date modifier
    • dates

All conditions must use a keyword to indicate what type of condition is to be used, and a comparator and value to describe a relationship that defines the condition such as "country equals Ireland". Some conditions have an option such as hits for location and tags that also takes a comparator and value, for example "tag Facebook sign-in hit more than 10 times". Some conditions also support date modifiers to link the condition to a time period. There are two options: date range, or a number of days ago. For example "tag Facebook sign-in hit more than 10 times from the 1st to the 30th of Feb".

Overall length of a segment cannot exceed 262,144 characters.

A full break down of condition options is given in the following table:

KeywordComparatorOptionDate Modifier
segmentequals a specific segment ID
tagsequals a specific tag ID/titlehits more than, less than or equal to a number of timesdaterange or days ago, optional if not used defaults to all time
tags_flagequals a specific flag ID/titlestatus on/off
tags_attributeequals a specific tag ID/title that is an attribute with a specific valuevalue equals, not equals, more than, less than
tags_attribute_datea specific tag ID/title that is a date attribute with a specific valuevalue relates to date with options - in the last, prior to, and in date rangeinteger number of days/hours/minutes,integer number of days/hours/minutes ago, and daterange
locationsequals a specific location IDhits more than, less than or equal to a number of timesdaterange or days ago, optional if not used defaults to all time
app_openedmore than, less than or equal to a number of timesdaterange or days ago, optional if not used defaults to all time
app_last_openedwithin time period set using date modifierdaterange or days ago
app_downloadedwithin time period set using date modifierdaterange or days ago
countryEqual or not equal to a two character country code (ISO 3166-1 alpha-2), eg. ["country", "=", "IE"]
languageEqual or not equal to a devices selected language (ISO 3166-1 alpha-2), eg. [ "language", "=", "Spanish" ]
carrier_nameEqual or not equal to a carrier or mobile network operator, eg. [ "carrier_name", "!=", "T-Mobile" ]
device_osEqual or not equal to specific device OS, eg. [ "device_os", "!=", "8.2" ]
device_modelEqual or not equal to specific device model, e.g. [ "device_model", "=", "iPhone 6" ]
app_versionEqual or not equal to specific app version, eg. [ "app_version", "=", "8.2" ]
idXtremepush ID, or in or not in a list of IDs, eg. [ "id", "in", [ID1, ID2, ...] ]
tokenEqual or not equal to a specific device token, or in or not in a list of tokens, eg. [ "token", "=", "TOKEN" ]
device_idEqual or not equal to a specific device ID (IDFV on iOS or Android ID on Android, or in or not in a list of device IDs, eg. [ "device_id", "=", "DEVICE_ID" ]

Condition examples

Tags:

[
    "tags", 
    "=",
    "TAG_ID or TAG_TITLE",
    ["hits", "> / < / =", "number of hits"]
    daterange or days ago (optional) (see examples below)
]

Flags:

[
    "tags_flag",
    "=",
    "TAG_ID or TAG_TITLE",
    ["status", "=", "on / off"]
]

Attributes:

[
    "tags_attributes",
    "=",
    "TAG_ID or TAG_TITLE",
 ["value", "> / < / = / !=", "some value"]
]

Date Attributes:

[
    "tags_attributes",
    "=",
    "TAG_ID or TAG_TITLE",
    null, 
   ["date", "in_the_last", ["2","days/hours/minutes"]],
]

Locations:

[
    "locations", 
    "=",
    "LOCATION_ID",
    ["hits", "> / < / =", "number of hits"],
    daterange or days ago (optional) (see examples below)
]

App opened all time:

[
    "app_opened",
    "> / < / =",
    "10"
]

App opened with date range:

[
    "app_opened",
    "> / < / =",
    "10",
    null,
    daterange or days ago (see examples below)
]

App downloaded:

[
    "app_downloaded",
    null,
    null,
    daterange or days ago (see examples below)
]

Daterange format:

["daterange", "between", "2015-01-01 to 2015-01-30", "2015-01-01", "2015-01-30"]

Days ago format:

["days_ago", "> / < / =", null, null, null, "10"]

Example

A segment combining a tag, the number of days since the app was downloaded and a country:

curl --request POST \
  --url https://external-api.xtremepush.com/api/external/create/segment \
  --header 'content-type: application/json' \
  --data '{
    "apptoken": "YOUR_APPTOKEN",
    "title": "Test",
    "conditions":  {
      "operator": "AND",
      "0": {
        "operator": "AND",
        "0": [
          "tags",
          "=",
          "test",
          ["hits", ">", "5"],
          ["daterange", "between", "2015-01-01 to 2015-01-30", "2015-01-01", "2015-01-30"]            
        ],
        "1": [
          "app_downloaded",
          null,
          null,
          ["days_ago", ">", null, null, null, 10]
        ],
        "2": [
          "country",
          "=",
          "IE"
        ]
      }
    }
  }'