core/v2/apikeys
NOTE: Requests to core/v2/apikeys endpoints require you to authenticate with a Sensu API key or access token.
The code examples in this document use the environment variable $SENSU_API_KEY to represent a valid API key in API requests.
Get all API keys
The /apikeys GET endpoint retrieves all API keys.
Example
The following example demonstrates a GET request to the /apikeys API endpoint:
curl -X GET \
http://127.0.0.1:8080/api/core/v2/apikeys \
-H "Authorization: Key $SENSU_API_KEY"The request will result in a successful HTTP/1.1 200 OK response and a JSON array that contains all API keys, similar to this example:
[
{
"metadata": {
"name": "83abef1e-e7d7-4beb-91fc-79ad90084d5b",
"created_by": "admin"
},
"username": "admin",
"created_at": 1570640363
},
{
"metadata": {
"name": "94jhid83j-96kg-2ewr-bab3-ppd3d49tdd94",
"created_by": "admin"
},
"username": "admin",
"created_at": 1651257929
}
]API Specification
| /apikeys (GET) | |
|---|---|
| description | Returns the list of API keys. |
| example url | http://hostname:8080/api/core/v2/apikeys |
| pagination | This endpoint supports pagination using the limit and continue query parameters. Read the API overview for details. |
| response type | Array |
| response codes |
|
| output | |
Create a new API key
The /apikeys API endpoint provides HTTP POST access to create a new API key.
Example
In the following example, an HTTP POST request is submitted to the /apikeys API endpoint to create a new API key.
NOTE: For the /apikeys POST endpoint, authenticate with a Sensu access token, which you can generate with /auth API endpoints or sensuctl.
This example uses $SENSU_ACCESS_TOKEN to represent a valid Sensu access token.
If you prefer, you can create a new API key with sensuctl instead of using this endpoint.
curl -X POST \
-H "Authorization: Bearer $SENSU_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"username": "admin"
}' \
http://127.0.0.1:8080/api/core/v2/apikeysThe request returns a successful HTTP HTTP/1.1 201 Created response, along with a Location header that contains the relative path to the new API key.
API Specification
| /apikeys (POST) | |
|---|---|
| description | Creates a new API key, a Sensu-generated universally unique identifier (UUID). The response will include HTTP 201 and a Location header that contains the relative path to the new API key. |
| example URL | http://hostname:8080/api/core/v2/apikeys |
| request payload | |
| response codes |
|
Get a specific API key
The /apikeys/:apikey GET endpoint retrieves the specified API key.
Example
The following example queries the /apikeys/:apikey API:
curl -X GET \
http://127.0.0.1:8080/api/core/v2/apikeys/83abef1e-e7d7-4beb-91fc-79ad90084d5b \
-H "Authorization: Key $SENSU_API_KEY"The request returns a successful HTTP/1.1 200 OK response and the requested :apikey definition, similar to the example below, or an error if the key is not found:
{
"metadata": {
"name": "83abef1e-e7d7-4beb-91fc-79ad90084d5b",
"created_by": "admin"
},
"username": "admin",
"created_at": 1570640363
}API Specification
| /apikeys/:apikey (GET) | |
|---|---|
| description | Returns the specified API key. |
| example url | http://hostname:8080/api/core/v2/apikeys/83abef1e-e7d7-4beb-91fc-79ad90084d5b |
| response type | Map |
| response codes |
|
| output | |
Update an API key with PATCH
The /apikeys/:apikey PATCH endpoint updates the specified API key.
NOTE: You cannot change a resource’s name or namespace with a PATCH request.
Example
The following example queries the /apikeys/:apikey API updates the username for the specified :apikey definition and returns a successful HTTP/1.1 200 OK response.
We support JSON merge patches, so you must set the Content-Type header to application/merge-patch+json for PATCH requests.
curl -X PATCH \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/merge-patch+json' \
{
"username": "devteam"
} \
http://127.0.0.1:8080/api/core/v2/apikeys/83abef1e-e7d7-4beb-91fc-79ad90084d5bAPI Specification
| /apikeys/:apikey (PATCH) | |
|---|---|
| description | Updates the specified API key. |
| example url | http://hostname:8080/api/core/v2/apikeys/83abef1e-e7d7-4beb-91fc-79ad90084d5b |
| response type | Map |
| response codes |
|
| output | |
Delete an API key
The /apikeys/:apikey API endpoint provides HTTP DELETE access to remove an API key.
Example
The following example shows a request to the /apikeys/:apikey API endpoint to delete the API key 83abef1e-e7d7-4beb-91fc-79ad90084d5b, resulting in a successful HTTP/1.1 204 No Content response.
curl -X DELETE \
-H "Authorization: Key $SENSU_API_KEY" \
http://127.0.0.1:8080/api/core/v2/apikeys/83abef1e-e7d7-4beb-91fc-79ad90084d5bAPI Specification
| /apikeys/:apikey (DELETE) | |
|---|---|
| description | Revokes the specified API key. |
| example URL | http://hostname:8080/api/core/v2/apikeys/83abef1e-e7d7-4beb-91fc-79ad90084d5b |
| response codes |
|