Invalidate API key API

Invalidates one or more API keys.

Request

DELETE /_security/api_key

Prerequisites

  • To use this API, you must have at least the manage_api_key cluster privilege.

Description

The API keys created by create API Key can be invalidated using this API.

Request body

The following parameters can be specified in the body of a DELETE request and pertain to invalidating api keys:

id

(Optional, string) An API key id. This parameter cannot be used with any of name, realm_name or username are used.

name

(Optional, string) An API key name. This parameter cannot be used with any of id, realm_name or username are used.

realm_name

(Optional, string) The name of an authentication realm. This parameter cannot be used with either id or name or when owner flag is set to true.

username

(Optional, string) The username of a user. This parameter cannot be used with either id or name or when owner flag is set to true.

owner

(Optional, boolean) A boolean flag that can be used to query API keys owned by the currently authenticated user. Defaults to false. The realm_name or username parameters cannot be specified when this parameter is set to true as they are assumed to be the currently authenticated ones.

At least one of “id”, “name”, “username” and “realm_name” must be specified if “owner” is “false” (default).

Response body

A successful call returns a JSON structure that contains the ids of the API keys that were invalidated, the ids of the API keys that had already been invalidated, and potentially a list of errors encountered while invalidating specific api keys.

Examples

If you create an API key as follows:

  1. POST /_security/api_key
  2. {
  3. "name": "my-api-key"
  4. }

A successful call returns a JSON structure that provides API key information. For example:

  1. {
  2. "id":"VuaCfGcBCdbkQm-e5aOx",
  3. "name":"my-api-key",
  4. "api_key":"ui2lp2axTNmsyakw9tvNnw"
  5. }

The following example invalidates the API key identified by specified id immediately:

  1. DELETE /_security/api_key
  2. {
  3. "id" : "VuaCfGcBCdbkQm-e5aOx"
  4. }

The following example invalidates the API key identified by specified name immediately:

  1. DELETE /_security/api_key
  2. {
  3. "name" : "my-api-key"
  4. }

The following example invalidates all API keys for the native1 realm immediately:

  1. DELETE /_security/api_key
  2. {
  3. "realm_name" : "native1"
  4. }

The following example invalidates all API keys for the user myuser in all realms immediately:

  1. DELETE /_security/api_key
  2. {
  3. "username" : "myuser"
  4. }

The following example invalidates the API key identified by the specified id if it is owned by the currently authenticated user immediately:

  1. DELETE /_security/api_key
  2. {
  3. "id" : "VuaCfGcBCdbkQm-e5aOx",
  4. "owner" : "true"
  5. }

The following example invalidates all API keys owned by the currently authenticated user immediately:

  1. DELETE /_security/api_key
  2. {
  3. "owner" : "true"
  4. }

Finally, the following example invalidates all API keys for the user myuser in the native1 realm immediately:

  1. DELETE /_security/api_key
  2. {
  3. "username" : "myuser",
  4. "realm_name" : "native1"
  5. }
  1. {
  2. "invalidated_api_keys": [
  3. "api-key-id-1"
  4. ],
  5. "previously_invalidated_api_keys": [
  6. "api-key-id-2",
  7. "api-key-id-3"
  8. ],
  9. "error_count": 2,
  10. "error_details": [
  11. {
  12. "type": "exception",
  13. "reason": "error occurred while invalidating api keys",
  14. "caused_by": {
  15. "type": "illegal_argument_exception",
  16. "reason": "invalid api key id"
  17. }
  18. },
  19. {
  20. "type": "exception",
  21. "reason": "error occurred while invalidating api keys",
  22. "caused_by": {
  23. "type": "illegal_argument_exception",
  24. "reason": "invalid api key id"
  25. }
  26. }
  27. ]
  28. }

The IDs of the API keys that were invalidated as part of this request.

The IDs of the API keys that were already invalidated.

The number of errors that were encountered when invalidating the API keys.

Details about these errors. This field is not present in the response when error_count is 0.