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.
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"] } } ] } }'
{ "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.
| Field | Type | Description |
|---|---|---|
|
enum |
Logical operator combining conditions: |
|
array |
Array of condition objects |
Condition types
Property condition
Evaluates a named property against a value.
| Field | Type | Description |
|---|---|---|
|
string |
Property name to evaluate |
|
string |
Comparison operator (see Operators below) |
|
any |
Value to compare against (not required for |
Operators
| Operator | Type | Description |
|---|---|---|
|
Boolean |
Property has no value |
|
Boolean |
Boolean property is true |
|
Boolean |
Boolean property is false |
|
Comparison |
Equals |
|
Comparison |
Not equals |
|
Comparison |
Greater than |
|
Comparison |
Greater than or equal |
|
Comparison |
Less than |
|
Comparison |
Less than or equal |
|
Array |
Value is in the provided array |
|
String |
Matches regular expression |
|
Semver |
Version equals |
|
Semver |
Version not equals |
|
Semver |
Version greater than |
|
Semver |
Version greater than or equal |
|
Semver |
Version less than |
|
Semver |
Version less than or equal |