When you need to automate user segmentation for feature-flag targeting, use this target group API example to create and manage target groups programmatically. This example demonstrates how to define advanced criteria, such as age or location, so you can consistently roll out features to the right audience and maintain parity across your environments.

Example: Create a target group

Create a new target group for advanced targeting rules.

Request
curl -X POST 'https://api.cloudbees.io/v2/applications/<applicationId>/target-groups' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <personal_access_token>' \ --data '{ "name": "BetaTesters", "conditions": { "allOf": [ { "property": { "name": "age", "operator": "gte", "operands": [18] } }, { "property": { "name": "country", "operator": "in-array", "operands": ["US", "CA"] } } ] } }'
Response
{ "targetGroup": { "id": "12345678-1234-5678-1234-56781234abcd", "name": "BetaTesters", "conditions": { "allOf": [ { "property": { "name": "age", "operator": "gte", "operands": [18] } }, { "property": { "name": "country", "operator": "in-array", "operands": ["US", "CA"] } } ] } } }

The conditions object

The conditions object defines the targeting logic for a target group. It is not exposed in the API reference site and is documented here for reference.

{ "operator": "and | or", "conditions": [Condition] }
Field Type Description

operator

enum

Logical operator combining conditions: and or or

conditions

array

Array of condition objects

Condition types

Property condition

Evaluates a named property against a value.

{ "property": "string", "operator": "string", "operand": "any" }
Field Type Description

property

string

Property name to evaluate

operator

string

Comparison operator (see Operators below)

operand

any

Value to compare against (not required for is-true, is-false, is-undefined)

Group condition

Evaluates against a named group.

{ "group": { "name": "string | [string]", "operator": "and | or | not" }, "value": "any" }

Dependency condition

Evaluates against the value of another flag.

{ "dependency": { "flag": "string", "value": "any" }, "value": "any" }

Version condition

Evaluates a semantic version property.

{ "version": { "operator": "string", "semver": "string" }, "value": "any" }

Operators

Operator Type Description

is-undefined

Boolean

Property has no value

is-true

Boolean

Boolean property is true

is-false

Boolean

Boolean property is false

eq

Comparison

Equals

ne

Comparison

Not equals

gt

Comparison

Greater than

gte

Comparison

Greater than or equal

lt

Comparison

Less than

lte

Comparison

Less than or equal

in-array

Array

Value is in the provided array

regex

String

Matches regular expression

semver-eq

Semver

Version equals

semver-ne

Semver

Version not equals

semver-gt

Semver

Version greater than

semver-gte

Semver

Version greater than or equal

semver-lt

Semver

Version less than

semver-lte

Semver

Version less than or equal