Skip to content

Latest commit

 

History

History
588 lines (472 loc) · 29.1 KB

ContextsApi.md

File metadata and controls

588 lines (472 loc) · 29.1 KB

ContextsApi

All URIs are relative to https://app.launchdarkly.com

Method HTTP request Description
evaluateContextInstance POST /api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate Evaluate flags for context instance
getContextAttributeNames GET /api/v2/projects/{projectKey}/environments/{environmentKey}/context-attributes Get context attribute names
getContextAttributeValues GET /api/v2/projects/{projectKey}/environments/{environmentKey}/context-attributes/{attributeName} Get context attribute values
getContextKindsByProjectKey GET /api/v2/projects/{projectKey}/context-kinds Get context kinds
getContexts GET /api/v2/projects/{projectKey}/environments/{environmentKey}/contexts/{kind}/{key} Get contexts
putContextKind PUT /api/v2/projects/{projectKey}/context-kinds/{key} Create or update context kind
searchContexts POST /api/v2/projects/{projectKey}/environments/{environmentKey}/contexts/search Search for contexts

evaluateContextInstance

ContextInstanceEvaluations evaluateContextInstance(projectKey, environmentKey, requestBody, limit, offset, sort, filter)

Evaluate flags for context instance

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: - `query` filters for a string that matches against the flags' keys and names. It is not case sensitive. For example: `filter=query equals dark-mode`. - `tags` filters 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`.

Example

// Import classes:
import com.launchdarkly.api.ApiClient;
import com.launchdarkly.api.ApiException;
import com.launchdarkly.api.Configuration;
import com.launchdarkly.api.auth.*;
import com.launchdarkly.api.models.*;
import com.launchdarkly.api.api.ContextsApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://app.launchdarkly.com");
    
    // Configure API key authorization: ApiKey
    ApiKeyAuth ApiKey = (ApiKeyAuth) defaultClient.getAuthentication("ApiKey");
    ApiKey.setApiKey("YOUR API KEY");
    // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
    //ApiKey.setApiKeyPrefix("Token");

    ContextsApi apiInstance = new ContextsApi(defaultClient);
    String projectKey = "projectKey_example"; // String | The project key
    String environmentKey = "environmentKey_example"; // String | The environment key
    Map<String, Object> requestBody = {"key":"user-key-123abc","kind":"user","otherAttribute":"other attribute value"}; // Map<String, Object> | 
    Long limit = 56L; // Long | The number of feature flags to return. Defaults to -1, which returns all flags
    Long offset = 56L; // Long | 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`.
    String sort = "sort_example"; // String | A comma-separated list of fields to sort by. Fields prefixed by a dash ( - ) sort in descending order
    String filter = "filter_example"; // String | A comma-separated list of filters. Each filter is of the form `field operator value`. Supported fields are explained above.
    try {
      ContextInstanceEvaluations result = apiInstance.evaluateContextInstance(projectKey, environmentKey, requestBody, limit, offset, sort, filter);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ContextsApi#evaluateContextInstance");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Parameters

Name Type Description Notes
projectKey String The project key
environmentKey String The environment key
requestBody Map<String, Object>
limit Long The number of feature flags to return. Defaults to -1, which returns all flags [optional]
offset Long 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`. [optional]
sort String A comma-separated list of fields to sort by. Fields prefixed by a dash ( - ) sort in descending order [optional]
filter String A comma-separated list of filters. Each filter is of the form `field operator value`. Supported fields are explained above. [optional]

Return type

ContextInstanceEvaluations

Authorization

ApiKey

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

HTTP response details

Status code Description Response headers
200 Flag evaluation collection response -
400 Invalid request -
401 Invalid access token -
403 Forbidden -
404 Invalid resource identifier -
429 Rate limited -

getContextAttributeNames

ContextAttributeNamesCollection getContextAttributeNames(projectKey, environmentKey, filter, limit)

Get context attribute names

Get context attribute names.

Example

// Import classes:
import com.launchdarkly.api.ApiClient;
import com.launchdarkly.api.ApiException;
import com.launchdarkly.api.Configuration;
import com.launchdarkly.api.auth.*;
import com.launchdarkly.api.models.*;
import com.launchdarkly.api.api.ContextsApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://app.launchdarkly.com");
    
    // Configure API key authorization: ApiKey
    ApiKeyAuth ApiKey = (ApiKeyAuth) defaultClient.getAuthentication("ApiKey");
    ApiKey.setApiKey("YOUR API KEY");
    // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
    //ApiKey.setApiKeyPrefix("Token");

    ContextsApi apiInstance = new ContextsApi(defaultClient);
    String projectKey = "projectKey_example"; // String | The project key
    String environmentKey = "environmentKey_example"; // String | The environment key
    String filter = "filter_example"; // String | A comma-separated list of context filters. This endpoint only accepts `kind` filters, with the `equals` operator, and `name` filters, with the `startsWith` operator. To learn more about the filter syntax, read [Filtering contexts](https://launchdarkly.com/docs/ld-docs/api/contexts#filtering-contexts).
    Long limit = 56L; // Long | Specifies the maximum number of items in the collection to return (max: 100, default: 100)
    try {
      ContextAttributeNamesCollection result = apiInstance.getContextAttributeNames(projectKey, environmentKey, filter, limit);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ContextsApi#getContextAttributeNames");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Parameters

Name Type Description Notes
projectKey String The project key
environmentKey String The environment key
filter String A comma-separated list of context filters. This endpoint only accepts `kind` filters, with the `equals` operator, and `name` filters, with the `startsWith` operator. To learn more about the filter syntax, read Filtering contexts. [optional]
limit Long Specifies the maximum number of items in the collection to return (max: 100, default: 100) [optional]

Return type

ContextAttributeNamesCollection

Authorization

ApiKey

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

HTTP response details

Status code Description Response headers
200 Context attribute names collection response -
400 Invalid request -
401 Invalid access token -
403 Forbidden -
429 Rate limited -

getContextAttributeValues

ContextAttributeValuesCollection getContextAttributeValues(projectKey, environmentKey, attributeName, filter, limit)

Get context attribute values

Get context attribute values.

Example

// Import classes:
import com.launchdarkly.api.ApiClient;
import com.launchdarkly.api.ApiException;
import com.launchdarkly.api.Configuration;
import com.launchdarkly.api.auth.*;
import com.launchdarkly.api.models.*;
import com.launchdarkly.api.api.ContextsApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://app.launchdarkly.com");
    
    // Configure API key authorization: ApiKey
    ApiKeyAuth ApiKey = (ApiKeyAuth) defaultClient.getAuthentication("ApiKey");
    ApiKey.setApiKey("YOUR API KEY");
    // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
    //ApiKey.setApiKeyPrefix("Token");

    ContextsApi apiInstance = new ContextsApi(defaultClient);
    String projectKey = "projectKey_example"; // String | The project key
    String environmentKey = "environmentKey_example"; // String | The environment key
    String attributeName = "attributeName_example"; // String | The attribute name
    String filter = "filter_example"; // String | A comma-separated list of context filters. This endpoint requires a `kind` filter, with the `equals` operator, and also accepts a `value` filter, with the `startsWith` operator. To learn more about the filter syntax, read [Filtering contexts](https://launchdarkly.com/docs/ld-docs/api/contexts#filtering-contexts).
    Long limit = 56L; // Long | Specifies the maximum number of items in the collection to return (max: 100, default: 50)
    try {
      ContextAttributeValuesCollection result = apiInstance.getContextAttributeValues(projectKey, environmentKey, attributeName, filter, limit);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ContextsApi#getContextAttributeValues");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Parameters

Name Type Description Notes
projectKey String The project key
environmentKey String The environment key
attributeName String The attribute name
filter String A comma-separated list of context filters. This endpoint requires a `kind` filter, with the `equals` operator, and also accepts a `value` filter, with the `startsWith` operator. To learn more about the filter syntax, read Filtering contexts. [optional]
limit Long Specifies the maximum number of items in the collection to return (max: 100, default: 50) [optional]

Return type

ContextAttributeValuesCollection

Authorization

ApiKey

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

HTTP response details

Status code Description Response headers
200 Context attribute values collection response -
400 Invalid request -
401 Invalid access token -
403 Forbidden -
429 Rate limited -

getContextKindsByProjectKey

ContextKindsCollectionRep getContextKindsByProjectKey(projectKey, expand)

Get context kinds

Get all context kinds for a given project.

Example

// Import classes:
import com.launchdarkly.api.ApiClient;
import com.launchdarkly.api.ApiException;
import com.launchdarkly.api.Configuration;
import com.launchdarkly.api.auth.*;
import com.launchdarkly.api.models.*;
import com.launchdarkly.api.api.ContextsApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://app.launchdarkly.com");
    
    // Configure API key authorization: ApiKey
    ApiKeyAuth ApiKey = (ApiKeyAuth) defaultClient.getAuthentication("ApiKey");
    ApiKey.setApiKey("YOUR API KEY");
    // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
    //ApiKey.setApiKeyPrefix("Token");

    ContextsApi apiInstance = new ContextsApi(defaultClient);
    String projectKey = "projectKey_example"; // String | The project key
    String expand = "expand_example"; // String | A comma-separated list of properties that can reveal additional information in the response. Options: `environmentObservations`.
    try {
      ContextKindsCollectionRep result = apiInstance.getContextKindsByProjectKey(projectKey, expand);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ContextsApi#getContextKindsByProjectKey");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Parameters

Name Type Description Notes
projectKey String The project key
expand String A comma-separated list of properties that can reveal additional information in the response. Options: `environmentObservations`. [optional]

Return type

ContextKindsCollectionRep

Authorization

ApiKey

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

HTTP response details

Status code Description Response headers
200 Context kinds collection response -
401 Invalid access token -
403 Forbidden -
404 Invalid resource identifier -

getContexts

Contexts getContexts(projectKey, environmentKey, kind, key, limit, continuationToken, sort, filter, includeTotalCount)

Get contexts

Get contexts based on kind and key. Returns one item for each application from which LaunchDarkly has received the context, with the `applicationId` field populated.

Example

// Import classes:
import com.launchdarkly.api.ApiClient;
import com.launchdarkly.api.ApiException;
import com.launchdarkly.api.Configuration;
import com.launchdarkly.api.auth.*;
import com.launchdarkly.api.models.*;
import com.launchdarkly.api.api.ContextsApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://app.launchdarkly.com");
    
    // Configure API key authorization: ApiKey
    ApiKeyAuth ApiKey = (ApiKeyAuth) defaultClient.getAuthentication("ApiKey");
    ApiKey.setApiKey("YOUR API KEY");
    // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
    //ApiKey.setApiKeyPrefix("Token");

    ContextsApi apiInstance = new ContextsApi(defaultClient);
    String projectKey = "projectKey_example"; // String | The project key
    String environmentKey = "environmentKey_example"; // String | The environment key
    String kind = "kind_example"; // String | The context kind
    String key = "key_example"; // String | The context key
    Long limit = 56L; // Long | Specifies the maximum number of items in the collection to return (max: 50, default: 20)
    String continuationToken = "continuationToken_example"; // String | An opaque cursor that identifies the next page of results. You can use this for pagination, however, we recommend using the `next` link we provide instead.
    String sort = "sort_example"; // String | Deprecated. This endpoint does not support sorting. Requests that include this parameter are rejected with a `400` response, so omit it. Results are always sorted by context kind and key.
    String filter = "filter_example"; // 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](https://launchdarkly.com/docs/ld-docs/api/contexts#filtering-contexts).
    Boolean includeTotalCount = true; // Boolean | Specifies whether to include or omit the total count of matching contexts. Defaults to true.
    try {
      Contexts result = apiInstance.getContexts(projectKey, environmentKey, kind, key, limit, continuationToken, sort, filter, includeTotalCount);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ContextsApi#getContexts");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Parameters

Name Type Description Notes
projectKey String The project key
environmentKey String The environment key
kind String The context kind
key String The context key
limit Long Specifies the maximum number of items in the collection to return (max: 50, default: 20) [optional]
continuationToken String An opaque cursor that identifies the next page of results. You can use this for pagination, however, we recommend using the `next` link we provide instead. [optional]
sort String Deprecated. This endpoint does not support sorting. Requests that include this parameter are rejected with a `400` response, so omit it. Results are always sorted by context kind and key. [optional]
filter 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. [optional]
includeTotalCount Boolean Specifies whether to include or omit the total count of matching contexts. Defaults to true. [optional]

Return type

Contexts

Authorization

ApiKey

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json

HTTP response details

Status code Description Response headers
200 Contexts collection response -
400 Invalid request -
401 Invalid access token -
403 Forbidden -
429 Rate limited -

putContextKind

UpsertResponseRep putContextKind(projectKey, key, upsertContextKindPayload)

Create or update context kind

Create or update a context kind by key. Only the included fields will be updated.

Example

// Import classes:
import com.launchdarkly.api.ApiClient;
import com.launchdarkly.api.ApiException;
import com.launchdarkly.api.Configuration;
import com.launchdarkly.api.auth.*;
import com.launchdarkly.api.models.*;
import com.launchdarkly.api.api.ContextsApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://app.launchdarkly.com");
    
    // Configure API key authorization: ApiKey
    ApiKeyAuth ApiKey = (ApiKeyAuth) defaultClient.getAuthentication("ApiKey");
    ApiKey.setApiKey("YOUR API KEY");
    // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
    //ApiKey.setApiKeyPrefix("Token");

    ContextsApi apiInstance = new ContextsApi(defaultClient);
    String projectKey = "projectKey_example"; // String | The project key
    String key = "key_example"; // String | The context kind key
    UpsertContextKindPayload upsertContextKindPayload = new UpsertContextKindPayload(); // UpsertContextKindPayload | 
    try {
      UpsertResponseRep result = apiInstance.putContextKind(projectKey, key, upsertContextKindPayload);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ContextsApi#putContextKind");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Parameters

Name Type Description Notes
projectKey String The project key
key String The context kind key
upsertContextKindPayload UpsertContextKindPayload

Return type

UpsertResponseRep

Authorization

ApiKey

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

HTTP response details

Status code Description Response headers
200 Context kind upsert response -
400 Invalid request -
401 Invalid access token -
403 Forbidden -
404 Invalid resource identifier -

searchContexts

Contexts searchContexts(projectKey, environmentKey, contextSearch, limit, continuationToken, sort, filter, includeTotalCount)

Search for contexts

Search for contexts. You can use either the query parameters or the request body parameters. If both are provided, there is an error. Results are sorted by context kind and key. Each context appears once, with its most recently reported attributes. Results include contexts that LaunchDarkly has received within the last 30 days. To learn more about the filter syntax, read Filtering contexts. To learn more about contexts, read Contexts.

Example

// Import classes:
import com.launchdarkly.api.ApiClient;
import com.launchdarkly.api.ApiException;
import com.launchdarkly.api.Configuration;
import com.launchdarkly.api.auth.*;
import com.launchdarkly.api.models.*;
import com.launchdarkly.api.api.ContextsApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://app.launchdarkly.com");
    
    // Configure API key authorization: ApiKey
    ApiKeyAuth ApiKey = (ApiKeyAuth) defaultClient.getAuthentication("ApiKey");
    ApiKey.setApiKey("YOUR API KEY");
    // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
    //ApiKey.setApiKeyPrefix("Token");

    ContextsApi apiInstance = new ContextsApi(defaultClient);
    String projectKey = "projectKey_example"; // String | The project key
    String environmentKey = "environmentKey_example"; // String | The environment key
    ContextSearch contextSearch = new ContextSearch(); // ContextSearch | 
    Long limit = 56L; // Long | Specifies the maximum number of items in the collection to return (max: 50, default: 20)
    String continuationToken = "continuationToken_example"; // String | An opaque cursor that identifies the next page of results. You can use this for pagination, however, we recommend using the `next` link we provide instead.
    String sort = "sort_example"; // String | Deprecated. This endpoint does not support sorting. Requests that include this parameter are rejected with a `400` response, so omit it. Results are always sorted by context kind and key.
    String filter = "filter_example"; // String | A comma-separated list of context filters. To learn more about the filter syntax, read [Filtering contexts](https://launchdarkly.com/docs/ld-docs/api/contexts#filtering-contexts).
    Boolean includeTotalCount = true; // Boolean | Specifies whether to include or omit the total count of matching contexts. Defaults to true. The total count is approximate and may be omitted if it is unavailable.
    try {
      Contexts result = apiInstance.searchContexts(projectKey, environmentKey, contextSearch, limit, continuationToken, sort, filter, includeTotalCount);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ContextsApi#searchContexts");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Parameters

Name Type Description Notes
projectKey String The project key
environmentKey String The environment key
contextSearch ContextSearch
limit Long Specifies the maximum number of items in the collection to return (max: 50, default: 20) [optional]
continuationToken String An opaque cursor that identifies the next page of results. You can use this for pagination, however, we recommend using the `next` link we provide instead. [optional]
sort String Deprecated. This endpoint does not support sorting. Requests that include this parameter are rejected with a `400` response, so omit it. Results are always sorted by context kind and key. [optional]
filter String A comma-separated list of context filters. To learn more about the filter syntax, read Filtering contexts. [optional]
includeTotalCount Boolean Specifies whether to include or omit the total count of matching contexts. Defaults to true. The total count is approximate and may be omitted if it is unavailable. [optional]

Return type

Contexts

Authorization

ApiKey

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

HTTP response details

Status code Description Response headers
200 Contexts collection response -
400 Invalid request -
401 Invalid access token -
403 Forbidden -
429 Rate limited -