---
title: "Search for context instances"
method: POST
path: "/api/v2/projects/{projectKey}/environments/{environmentKey}/context-instances/search"
tags: ["Contexts"]
---

# Search for context instances

`POST /api/v2/projects/{projectKey}/environments/{environmentKey}/context-instances/search`

Search for context instances.

You can use either the query parameters or the request body parameters. If both are provided, there is an error.

To learn more about the filter syntax, read [Filtering contexts and context instances](https://launchdarkly.com/docs/api/contexts#filtering-contexts-and-context-instances). To learn more about context instances, read [Context instances](https://launchdarkly.com/docs/home/observability/multi-contexts#context-instances).

## Path parameters

- `projectKey` string, string, required — The project key
- `environmentKey` string, string, required — The environment key

## Query parameters

- `limit` integer — Specifies the maximum number of items in the collection to return (max: 50, default: 20)
- `continuationToken` string, string — Limits results to context instances with sort values after the value specified. You can use this for pagination, however, we recommend using the `next` link we provide instead.
- `sort` string, string — Specifies a field by which to sort. LaunchDarkly supports sorting by timestamp in ascending order by specifying `ts` for this value, or descending order by specifying `-ts`.
- `filter` string, string — A comma-separated list of context filters. This endpoint only accepts an `applicationId` filter. To learn more about the filter syntax, read [Filtering contexts and context instances](https://launchdarkly.com/docs/ld-docs/api/contexts#filtering-contexts-and-context-instances).
- `includeTotalCount` boolean — Specifies whether to include or omit the total count of matching context instances. Defaults to true.

## Request body

- ContextInstanceSearch
  - `filter` string — A collection of context instance filters
  - `sort` string — Specifies a field by which to sort. LaunchDarkly supports sorting by timestamp in ascending order by specifying <code>ts</code> for this value, or descending order by specifying <code>-ts</code>.
  - `limit` integer — Specifies the maximum number of items in the collection to return (max: 50, default: 20)
  - `continuationToken` string — Limits results to context instances with sort values after the value specified. You can use this for pagination, however, we recommend using the <code>next</code> link instead, because this value is an obfuscated string.

## Response `200`

Context instances collection response

- ContextInstances
  - `_links` object — The location and content type of related resources
  - `totalCount` integer — The number of unique context instances
  - `_environmentId` string, required — The environment ID
  - `continuationToken` string — An obfuscated string that references the last context instance on the previous page of results. You can use this for pagination, however, we recommend using the <code>next</code> link instead.
  - `items` ContextInstanceRecord[], required — A collection of context instances. Can include multiple versions of context instances that have the same <code>id</code>, but different <code>applicationId</code>s.
    - `lastSeen` string, date-time — Timestamp of the last time an evaluation occurred for this context instance
    - `id` string, required — The context instance ID
    - `applicationId` string — An identifier representing the application where the LaunchDarkly SDK is running
    - `anonymousKinds` string[] — A list of the context kinds this context was associated with that the SDK removed because they were marked as anonymous at flag evaluation
    - `context` string, required — The context, including its kind and attributes
    - `_links` object — The location and content type of related resources
    - `_access` Access
      - `denied` AccessDenied[], required
        - `action` string, required
        - `reason` AccessDeniedReason, required
          - `resources` string[] — Resource specifier strings
          - `notResources` string[] — Targeted resources are the resources NOT in this list. The <code>resources</code> and <code>notActions</code> fields must be empty to use this field.
          - `actions` ActionSpecifier[] — Actions to perform on a resource
          - `notActions` ActionSpecifier[] — Targeted actions are the actions NOT in this list. The <code>actions</code> and <code>notResources</code> fields must be empty to use this field.
          - `effect` 'allow' | 'deny', required — Whether this statement should allow or deny actions on the resources.
          - `role_name` string
      - `allowed` AccessAllowedRep[], required
        - `action` string, required
        - `reason` AccessAllowedReason, required
          - `resources` string[] — Resource specifier strings
          - `notResources` string[] — Targeted resources are the resources NOT in this list. The <code>resources</code> and <code>notActions</code> fields must be empty to use this field.
          - `actions` ActionSpecifier[] — Actions to perform on a resource
          - `notActions` ActionSpecifier[] — Targeted actions are the actions NOT in this list. The <code>actions</code> and <code>notResources</code> fields must be empty to use this field.
          - `effect` 'allow' | 'deny', required — Whether this statement should allow or deny actions on the resources.
          - `role_name` string

## Other responses

- `400` — Invalid request
- `401` — Invalid access token
- `403` — Forbidden
- `429` — Rate limited

---

[API](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api.md) · [All operations](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/launchdarkly/launchdarkly-rest-api/revisions/69c5c9aafe78/schema)
