Evaluate flags for context instance
For the complete documentation index, see llms.txt. For the full documentation snapshot, see llms-full.txt.
Evaluate flags for a context instance, for example, to determine the expected flag variation. Do not use this API instead of an SDK. The LaunchDarkly SDKs are specialized for the tasks of evaluating feature flags in your application at scale and generating analytics events based on those evaluations. This API is not designed for that use case. Any evaluations you perform with this API will not be reflected in features such as flag statuses and flag insights. Context instances evaluated by this API will not appear in the Contexts list. To learn more, read Comparing LaunchDarkly’s SDKs and REST API.
Filtering
LaunchDarkly supports the filter query param for filtering, with the following fields:
queryfilters for a string that matches against the flags’ keys and names. It is not case sensitive. For example:filter=query equals dark-mode.tagsfilters the list to flags that have all of the tags in the list. For example:filter=tags contains ["beta","q1"].
You can also apply multiple filters at once. For example, setting filter=query equals dark-mode, tags contains ["beta","q1"] matches flags which match the key or name dark-mode and are tagged beta and q1.
curl --request POST \
--url https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"key": "user-key-123abc",
"kind": "user",
"otherAttribute": "other attribute value"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate"
payload = {
"key": "user-key-123abc",
"kind": "user",
"otherAttribute": "other attribute value"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({key: 'user-key-123abc', kind: 'user', otherAttribute: 'other attribute value'})
};
fetch('https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'key' => 'user-key-123abc',
'kind' => 'user',
'otherAttribute' => 'other attribute value'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate"
payload := strings.NewReader("{\n \"key\": \"user-key-123abc\",\n \"kind\": \"user\",\n \"otherAttribute\": \"other attribute value\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"key\": \"user-key-123abc\",\n \"kind\": \"user\",\n \"otherAttribute\": \"other attribute value\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"key\": \"user-key-123abc\",\n \"kind\": \"user\",\n \"otherAttribute\": \"other attribute value\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
},
"site": {
"href": "/my-project/my-environment/features/sort.order/targeting",
"type": "text/html"
}
},
"_value": true,
"key": "sort.order",
"name": "SortOrder",
"reason": {
"kind": "FALLTHROUGH"
}
},
{
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
},
"site": {
"href": "/my-project/my-environment/features/alternate.page/targeting",
"type": "text/html"
}
},
"_value": false,
"key": "alternate.page",
"name": "AlternatePage",
"reason": {
"kind": "RULE_MATCH",
"ruleID": "b2530cdf-14c6-4e16-b660-00239e08f19b",
"ruleIndex": 1
}
}
],
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
}
},
"totalCount": 2
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Authorizations
Path Parameters
The project key
The environment key
Query Parameters
The number of feature flags to return. Defaults to -1, which returns all flags
Where to start in the list. Use this with pagination. For example, an offset of 10 skips the first ten items and then returns the next items in the list, up to the query limit.
A comma-separated list of fields to sort by. Fields prefixed by a dash ( - ) sort in descending order
A comma-separated list of filters. Each filter is of the form field operator value. Supported fields are explained above.
Body
Response
Flag evaluation collection response
Details on the flag evaluations for this context instance
Show child attributes
Show child attributes
[
{
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
},
"site": {
"href": "/my-project/my-environment/features/sort.order/targeting",
"type": "text/html"
}
},
"_value": true,
"key": "sort.order",
"name": "SortOrder",
"reason": { "kind": "FALLTHROUGH" }
},
{
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
},
"site": {
"href": "/my-project/my-environment/features/alternate.page/targeting",
"type": "text/html"
}
},
"_value": false,
"key": "alternate.page",
"name": "AlternatePage",
"reason": {
"kind": "RULE_MATCH",
"ruleID": "b2530cdf-14c6-4e16-b660-00239e08f19b",
"ruleIndex": 1
}
}
]
The location and content type of related resources
Show child attributes
Show child attributes
{
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
}
}
The number of flags
2
curl --request POST \
--url https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"key": "user-key-123abc",
"kind": "user",
"otherAttribute": "other attribute value"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate"
payload = {
"key": "user-key-123abc",
"kind": "user",
"otherAttribute": "other attribute value"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({key: 'user-key-123abc', kind: 'user', otherAttribute: 'other attribute value'})
};
fetch('https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'key' => 'user-key-123abc',
'kind' => 'user',
'otherAttribute' => 'other attribute value'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate"
payload := strings.NewReader("{\n \"key\": \"user-key-123abc\",\n \"kind\": \"user\",\n \"otherAttribute\": \"other attribute value\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"key\": \"user-key-123abc\",\n \"kind\": \"user\",\n \"otherAttribute\": \"other attribute value\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"key\": \"user-key-123abc\",\n \"kind\": \"user\",\n \"otherAttribute\": \"other attribute value\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
},
"site": {
"href": "/my-project/my-environment/features/sort.order/targeting",
"type": "text/html"
}
},
"_value": true,
"key": "sort.order",
"name": "SortOrder",
"reason": {
"kind": "FALLTHROUGH"
}
},
{
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
},
"site": {
"href": "/my-project/my-environment/features/alternate.page/targeting",
"type": "text/html"
}
},
"_value": false,
"key": "alternate.page",
"name": "AlternatePage",
"reason": {
"kind": "RULE_MATCH",
"ruleID": "b2530cdf-14c6-4e16-b660-00239e08f19b",
"ruleIndex": 1
}
}
],
"_links": {
"self": {
"href": "/api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate",
"type": "application/json"
}
},
"totalCount": 2
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}