Documentation Index
Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
Use this file to discover all available pages before exploring further.
Add targeting criteria to your segments to filter users based on attributes from the evaluation context.
See Targeting Criteria in the reference for details on operators, value types, and how criteria work.
Use Equality Matching
Match users where a field equals a specific value:
curl -X POST "https://flags.confidence.dev/v1/segments?segmentId=sweden-users" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"displayName": "Users from Sweden",
"targeting": {
"criteria": {
"sweden": {
"attribute": {
"attributeName": "country",
"eqRule": {
"value": {"stringValue": "SE"}
}
}
}
},
"expression": {"ref": "sweden"}
},
"allocation": {"proportion": {"value": "1.0"}}
}'
Use Set Matching
Match users where a field equals any value from a set:
curl -X POST "https://flags.confidence.dev/v1/segments?segmentId=nordic-users" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"displayName": "Nordic users",
"targeting": {
"criteria": {
"nordics": {
"attribute": {
"attributeName": "country",
"setRule": {
"values": [
{"stringValue": "SE"},
{"stringValue": "DK"},
{"stringValue": "NO"},
{"stringValue": "FI"},
{"stringValue": "IS"}
]
}
}
}
},
"expression": {"ref": "nordics"}
},
"allocation": {"proportion": {"value": "1.0"}}
}'
Use Range Matching
Match users where a field falls within a range:
curl -X POST "https://flags.confidence.dev/v1/segments?segmentId=age-40-49" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"displayName": "Users aged 40-49",
"targeting": {
"criteria": {
"age-range": {
"attribute": {
"attributeName": "age",
"rangeRule": {
"startInclusive": {"numberValue": 40},
"endExclusive": {"numberValue": 50}
}
}
}
},
"expression": {"ref": "age-range"}
},
"allocation": {"proportion": {"value": "1.0"}}
}'
Match Against Another Segment
Check if a user is in another segment:
curl -X POST "https://flags.confidence.dev/v1/segments?segmentId=premium-sweden" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"displayName": "Premium users from Sweden",
"targeting": {
"criteria": {
"sweden": {
"attribute": {
"attributeName": "country",
"eqRule": {"value": {"stringValue": "SE"}}
}
},
"premium": {
"segment": {"segment": "segments/premium-users"}
}
},
"expression": {
"and": {
"operands": [
{"ref": "sweden"},
{"ref": "premium"}
]
}
}
},
"allocation": {"proportion": {"value": "0.1"}}
}'
Combine Multiple Criteria
Use AND, OR, and NOT to create complex logic:
curl -X POST "https://flags.confidence.dev/v1/segments?segmentId=nordic-android" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"displayName": "Nordic Android users",
"targeting": {
"criteria": {
"nordics": {
"attribute": {
"attributeName": "country",
"setRule": {
"values": [
{"stringValue": "SE"},
{"stringValue": "DK"},
{"stringValue": "NO"},
{"stringValue": "FI"}
]
}
}
},
"ios": {
"attribute": {
"attributeName": "device.os",
"eqRule": {"value": {"stringValue": "ios"}}
}
}
},
"expression": {
"and": {
"operands": [
{"ref": "nordics"},
{"not": {"ref": "ios"}}
]
}
}
},
"allocation": {"proportion": {"value": "1.0"}}
}'
Use Nested Fields
Reference nested fields with dot notation:
curl -X POST "https://flags.confidence.dev/v1/segments?segmentId=iphone-users" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"displayName": "iPhone users",
"targeting": {
"criteria": {
"iphone": {
"attribute": {
"attributeName": "device.model",
"eqRule": {"value": {"stringValue": "iPhone14"}}
}
}
},
"expression": {"ref": "iphone"}
},
"allocation": {"proportion": {"value": "1.0"}}
}'
This matches against evaluation context like:
{
"user_id": "123",
"device": {
"model": "iPhone14",
"os": "ios"
}
}
Next Steps
After setting up targeting criteria:
- Coordinate segments to make them mutually exclusive
- Create flag rules to assign variants
- Resolve flags with the appropriate evaluation context