Affected: REST API
Overview
The LaunchDarkly REST API comprises a set of functions designed to facilitate specific tasks beyond the capabilities of the current LaunchDarkly UI. The API can be utilized to retrieve the latest expected flag variations for contexts within the context list.
Solution
To automate the process, create a custom script through a series of API calls:
-
Use the Search for contexts method to retrieve the full list of contexts.
Example:
curl -i -X POST \
'https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/contexts/search' \
-H 'Authorization: YOUR_API_KEY_HERE' \
-H 'Content-Type: application/json' \
-d '{
"filter": "*.name startsWith Jo,kind anyOf [\"user\",\"organization\"]",
"sort": "-ts",
"limit": 10,
"continuationToken": "QAGFKH1313KUGI2351"
}' -
Extract and save the
key
values into an organized list. -
Use the Evaluate flags for context instance method. This assesses the expected feature flag's value for each context key obtained in the prior step. Any evaluations performed with this API will not be reflected in features such as flag statuses and flag insights. Use the LaunchDarkly SDKs instead.
Example:curl -i -X POST \
'https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate' \
-H 'Authorization: YOUR_API_KEY_HERE' \
-H 'Content-Type: application/json' \
-d '{
"key": "user-key-123abc",
"kind": "user",
"otherAttribute": "other attribute value"
}'
By following these steps, in addition to tools such as jq, a command-line JSON processor, it's possible to efficiently filter, extract, and automate the way to obtain specific contexts' feature flag values for analysis.