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 PUT 'https://api.cloudbees.io/v2/applications/<applicationId>/target-groups/<targetGroupId>' \ --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"] } } ] } } }