Contexts are people, services, machines, or other resources that encounter feature flags in your product. Contexts are identified by their kind, which describes the type of resources encountering flags, and by their key. Each unique combination of one or more contexts that have encountered a feature flag in your product is called a context instance.
When you use the LaunchDarkly SDK to evaluate a flag, you provide a context to that call. LaunchDarkly records the key and attributes of each context instance. You can view these in the LaunchDarkly user interface from the Contexts list, or use the Context APIs. To learn more, read Contexts.
LaunchDarkly provides APIs for you to:
To learn more about context kinds, read Context kinds.
Contexts are always scoped within a project and an environment. Each environment has its own set of context instance records.
Several of the endpoints in the contexts API require a context instance ID or application ID. Both of these IDs are returned as part of the Search for context instances response. The context instance ID is the id field of each element in the items array. The application ID is the applicationId field of each element in the items array. By default, the application ID is set to the SDK you are using. In the LaunchDarkly UI, the application ID and application version appear on the context details page in the “From source” field. You can change the application ID as part of your SDK configuration. To learn more, read Application metadata configuration.
When you search for contexts or context instances, you can filter the results using fields and operators with the filter parameter. Specify filter either as a query parameter or as a request body parameter.
The filter parameter supports the following operators: after, anyOf, before, contains, equals, exists, notEquals, startsWith.
Returns contexts or context instances if the date field value occurs after the specified time. For example:
myField after "2022-09-21T19:03:15+00:00"Returns contexts or context instances if any field value matches any of the provided values. For example:
myField anyOf [44]myField anyOf ["phone","tablet"]myField anyOf [true]"Returns contexts or context instances if the date field value occurs before the provided time. For example:
myField before "2022-09-21T19:03:15+00:00"Returns contexts or context instances if the field’s list of values contains all of the provided values. For example:
myListField contains 44myListField contains ["phone","tablet"]myListField contains trueReturns contexts or context instances only if the field value exactly matches the provided value. For example:
myField equals 44myField equals "device"myField equals truemyField equals [1,2,3,4]myField equals ["hello","goodbye"]Returns contexts or context instances based on whether the specified field exists. For example:
myField exists truemyField exists false*.name exists trueReturns contexts or context instances if the field value does not exactly match the provided value. For example:
myField notEquals 44myField notEquals "device"myField notEquals truemyField notEquals [1,2,3,4]myField notEquals ["hello","goodbye"]Returns contexts or context instances if a singular string field value begins with the provided substring. For example:
myField startsWith "do"You can also combine filters in the following ways:
,) as an AND operator|) as an OR operator() to group filtersFor example:
myField notEquals 0, myField notEquals 1 returns contexts or context instances where myField is not 0 and is not 1myFirstField equals "device",(mySecondField equals "iPhone"|mySecondField equals "iPad") returns contexts or context instances where myFirstField is equal to “device” and mySecondField is equal to either “iPhone” or “iPad”The filter parameter accepts different field types depending on whether you search for contexts or context instances. Also, you can only filter some fields using certain operators.
When you search for contexts, the filter parameter supports the following fields and operators:
When searching for context instances, the filter parameter supports the following fields and operators: