List segment memberships for context instance
curl --request POST \
--url https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/evaluate \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"address": {
"city": "Springfield",
"street": "123 Main Street"
},
"jobFunction": "doctor",
"key": "context-key-123abc",
"kind": "user",
"name": "Sandy"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/evaluate"
payload = {
"address": {
"city": "Springfield",
"street": "123 Main Street"
},
"jobFunction": "doctor",
"key": "context-key-123abc",
"kind": "user",
"name": "Sandy"
}
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({
address: {city: 'Springfield', street: '123 Main Street'},
jobFunction: 'doctor',
key: 'context-key-123abc',
kind: 'user',
name: 'Sandy'
})
};
fetch('https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/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}/segments/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([
'address' => [
'city' => 'Springfield',
'street' => '123 Main Street'
],
'jobFunction' => 'doctor',
'key' => 'context-key-123abc',
'kind' => 'user',
'name' => 'Sandy'
]),
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}/segments/evaluate"
payload := strings.NewReader("{\n \"address\": {\n \"city\": \"Springfield\",\n \"street\": \"123 Main Street\"\n },\n \"jobFunction\": \"doctor\",\n \"key\": \"context-key-123abc\",\n \"kind\": \"user\",\n \"name\": \"Sandy\"\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}/segments/evaluate")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"address\": {\n \"city\": \"Springfield\",\n \"street\": \"123 Main Street\"\n },\n \"jobFunction\": \"doctor\",\n \"key\": \"context-key-123abc\",\n \"kind\": \"user\",\n \"name\": \"Sandy\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/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 \"address\": {\n \"city\": \"Springfield\",\n \"street\": \"123 Main Street\"\n },\n \"jobFunction\": \"doctor\",\n \"key\": \"context-key-123abc\",\n \"kind\": \"user\",\n \"name\": \"Sandy\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"name": "Segment Name",
"key": "segment-key-123abc",
"description": "Segment description",
"unbounded": false,
"external": "https://amplitude.com/myCohort",
"isMember": true,
"isIndividuallyTargeted": true,
"isRuleTargeted": false,
"_links": {}
}
],
"_links": {}
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "not_found",
"message": "Invalid resource identifier"
}List segment memberships for context instance
For a given context instance with attributes, get membership details for all segments. In the request body, pass in the context instance.
POST
/
api
/
v2
/
projects
/
{projectKey}
/
environments
/
{environmentKey}
/
segments
/
evaluate
List segment memberships for context instance
curl --request POST \
--url https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/evaluate \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"address": {
"city": "Springfield",
"street": "123 Main Street"
},
"jobFunction": "doctor",
"key": "context-key-123abc",
"kind": "user",
"name": "Sandy"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/evaluate"
payload = {
"address": {
"city": "Springfield",
"street": "123 Main Street"
},
"jobFunction": "doctor",
"key": "context-key-123abc",
"kind": "user",
"name": "Sandy"
}
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({
address: {city: 'Springfield', street: '123 Main Street'},
jobFunction: 'doctor',
key: 'context-key-123abc',
kind: 'user',
name: 'Sandy'
})
};
fetch('https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/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}/segments/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([
'address' => [
'city' => 'Springfield',
'street' => '123 Main Street'
],
'jobFunction' => 'doctor',
'key' => 'context-key-123abc',
'kind' => 'user',
'name' => 'Sandy'
]),
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}/segments/evaluate"
payload := strings.NewReader("{\n \"address\": {\n \"city\": \"Springfield\",\n \"street\": \"123 Main Street\"\n },\n \"jobFunction\": \"doctor\",\n \"key\": \"context-key-123abc\",\n \"kind\": \"user\",\n \"name\": \"Sandy\"\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}/segments/evaluate")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"address\": {\n \"city\": \"Springfield\",\n \"street\": \"123 Main Street\"\n },\n \"jobFunction\": \"doctor\",\n \"key\": \"context-key-123abc\",\n \"kind\": \"user\",\n \"name\": \"Sandy\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/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 \"address\": {\n \"city\": \"Springfield\",\n \"street\": \"123 Main Street\"\n },\n \"jobFunction\": \"doctor\",\n \"key\": \"context-key-123abc\",\n \"kind\": \"user\",\n \"name\": \"Sandy\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"name": "Segment Name",
"key": "segment-key-123abc",
"description": "Segment description",
"unbounded": false,
"external": "https://amplitude.com/myCohort",
"isMember": true,
"isIndividuallyTargeted": true,
"isRuleTargeted": false,
"_links": {}
}
],
"_links": {}
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "not_found",
"message": "Invalid resource identifier"
}Authorizations
Path Parameters
The project key
The environment key
Body
application/json