# List segment memberships for context instance

POST https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/segments/evaluate
Content-Type: application/json

For a given context instance with attributes, get membership details for all segments. In the request body, pass in the context instance.

Reference: https://launchdarkly.com/docs/api/segments/get-context-instance-segments-membership-by-env

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/environments/{environmentKey}/segments/evaluate:
    post:
      operationId: get-context-instance-segments-membership-by-env
      summary: List segment memberships for context instance
      description: >-
        For a given context instance with attributes, get membership details for
        all segments. In the request body, pass in the context instance.
      tags:
        - subpackage_segments
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: environmentKey
          in: path
          description: The environment key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Context instance segment membership collection response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextInstanceSegmentMemberships'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestErrorRep'
        '401':
          description: Invalid access token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorRep'
        '404':
          description: Invalid resource identifier
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorRep'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextInstance'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    ContextInstance:
      type: object
      additionalProperties:
        description: Any type
      title: ContextInstance
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    ContextInstanceSegmentMembership:
      type: object
      properties:
        name:
          type: string
          description: A human-friendly name for the segment
        key:
          type: string
          description: A unique key used to reference the segment
        description:
          type: string
          description: A description of the segment's purpose
        unbounded:
          type: boolean
          description: >-
            Whether this is an unbounded segment. Unbounded segments, also
            called big segments, may be list-based segments with more than
            15,000 entries, or synced segments.
        external:
          type: string
          description: If the segment is a synced segment, the name of the external source
        isMember:
          type: boolean
          description: >-
            Whether the context is a member of this segment, either by explicit
            inclusion or by rule matching
        isIndividuallyTargeted:
          type: boolean
          description: Whether the context is explicitly included in this segment
        isRuleTargeted:
          type: boolean
          description: >-
            Whether the context is captured by this segment's rules. The value
            of this field is undefined if the context is also explicitly
            included (<code>isIndividuallyTargeted</code> is <code>true</code>).
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - name
        - key
        - description
        - unbounded
        - external
        - isMember
        - isIndividuallyTargeted
        - isRuleTargeted
        - _links
      title: ContextInstanceSegmentMembership
    ContextInstanceSegmentMemberships:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/ContextInstanceSegmentMembership'
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - items
        - _links
      title: ContextInstanceSegmentMemberships
    InvalidRequestErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: InvalidRequestErrorRep
    UnauthorizedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: UnauthorizedErrorRep
    NotFoundErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: NotFoundErrorRep
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

```

## SDK Code Examples

```python
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": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/segments/evaluate';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"address":{"city":"Springfield","street":"123 Main Street"},"jobFunction":"doctor","key":"context-key-123abc","kind":"user","name":"Sandy"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
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", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
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"] = '<apiKey>'
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
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/segments/evaluate")
  .header("Authorization", "<apiKey>")
  .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();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/segments/evaluate', [
  'body' => '{
  "address": {
    "city": "Springfield",
    "street": "123 Main Street"
  },
  "jobFunction": "doctor",
  "key": "context-key-123abc",
  "kind": "user",
  "name": "Sandy"
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/segments/evaluate");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\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}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "address": [
    "city": "Springfield",
    "street": "123 Main Street"
  ],
  "jobFunction": "doctor",
  "key": "context-key-123abc",
  "kind": "user",
  "name": "Sandy"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/projectKey/environments/environmentKey/segments/evaluate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```