Get API Key information APIedit

API Key(s) information can be retrieved using this API.

Get API Key Requestedit

The GetApiKeyRequest supports retrieving API key information for

  1. A specific API key
  2. All API keys for a specific realm
  3. All API keys for a specific user
  4. All API keys for a specific user in a specific realm
  5. A specific key or all API keys owned by the current authenticated user
  6. All API keys if the user is authorized to do so

Retrieve a specific API key by its idedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyId(createApiKeyResponse1.getId(), false);

Retrieve a specific API key by its nameedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyName(createApiKeyResponse1.getName(), false);

Retrieve all API keys for given realmedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmName("default_file");

Retrieve all API keys for a given useredit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingUserName("test_user");

Retrieve all API keys for given user in a realmedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmAndUserName("default_file", "test_user");

Retrieve all API keys for the current authenticated useredit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.forOwnedApiKeys();

Retrieve all API keys if the user is authorized to do soedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.forAllApiKeys();

Synchronous executionedit

When executing a GetApiKeyRequest in the following manner, the client waits for the GetApiKeyResponse to be returned before continuing with code execution:

GetApiKeyResponse getApiKeyResponse =, RequestOptions.DEFAULT);

Synchronous calls may throw an IOException in case of either failing to parse the REST response in the high-level REST client, the request times out or similar cases where there is no response coming back from the server.

In cases where the server returns a 4xx or 5xx error code, the high-level client tries to parse the response body error details instead and then throws a generic ElasticsearchException and adds the original ResponseException as a suppressed exception to it.

Asynchronous executionedit

Executing a GetApiKeyRequest can also be done in an asynchronous fashion so that the client can return directly. Users need to specify how the response or potential failures will be handled by passing the request and a listener to the asynchronous get-api-key method:, RequestOptions.DEFAULT, listener); 

The GetApiKeyRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed. Failure scenarios and expected exceptions are the same as in the synchronous execution case.

A typical listener for get-api-key looks like:

listener = new ActionListener<GetApiKeyResponse>() {
    public void onResponse(GetApiKeyResponse getApiKeyResponse) {

    public void onFailure(Exception e) {

Called when the execution is successfully completed.

Called when the whole GetApiKeyRequest fails.

Get API Key information API Responseedit

The returned GetApiKeyResponse contains the information regarding the API keys that were requested.

Available using getApiKeyInfos, contains list of API keys that were retrieved for this request.
GetApiKeyResponse getApiKeyResponse =, RequestOptions.DEFAULT);