Get API Key information API
editGet API Key information API
editAPI Key(s) information can be retrieved using this API.
Get API Key Request
editThe GetApiKeyRequest
supports retrieving API key information for
- A specific API key
- All API keys for a specific realm
- All API keys for a specific user
- All API keys for a specific user in a specific realm
Retrieve a specific API key by its id
editGetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyId(createApiKeyResponse1.getId());
Retrieve a specific API key by its name
editGetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyName(createApiKeyResponse1.getName());
Retrieve all API keys for given realm
editGetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmName("default_file");
Retrieve all API keys for a given user
editGetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingUserName("test_user");
Retrieve all API keys for given user in a realm
editGetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmAndUserName("default_file", "test_user");
Synchronous Execution
editWhen executing a GetApiKeyRequest
in the following manner, the client waits
for the GetApiKeyResponse
to be returned before continuing with code execution:
GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, 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 Execution
editExecuting 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:
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:
Get API Key information API Response
editThe returned GetApiKeyResponse
contains the information regarding the API keys that were
requested.
-
api_keys
-
Available using
getApiKeyInfos
, contains list of API keys that were retrieved for this request.
GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT);