Namespaces API

NOTE: Requests to the namespaces API require you to authenticate with a Sensu access token or API key. The code examples in this document use the environment variable $SENSU_API_KEY to represent a valid API key in API requests.

Get all namespaces

The /namespaces API endpoint provides HTTP GET access to namespace data.

Example

The following example demonstrates a request to the /namespaces API endpoint, resulting in a JSON array that contains namespace definitions.

curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces \
-H "Authorization: Key $SENSU_API_KEY"

HTTP/1.1 200 OK
[
  {
    "name": "default"
  },
  {
    "name": "development"
  }
]

API Specification

/namespaces (GET)
description Returns the list of namespaces.
example url http://hostname:8080/api/core/v2/namespaces
pagination This endpoint supports pagination using the limit query parameter.
response filtering This endpoint supports API response filtering.
response type Array
response codes
  • Success: 200 (OK)
  • Error: 500 (Internal Server Error)
output
[
  {
    "name": "default"
  },
  {
    "name": "development"
  }
]

Create a new namespace

The /namespaces API endpoint provides HTTP POST access to create Sensu namespaces.

Example

In the following example, an HTTP POST request is submitted to the /namespaces API endpoint to create the namespace development. The request returns a successful HTTP 201 Created response.

curl -X POST \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
  "name": "development"
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/namespaces

HTTP/1.1 201 Created

API Specification

/namespaces (POST)
description Creates a Sensu namespace.
example URL http://hostname:8080/api/core/v2/namespaces
payload
{
  "name": "development"
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

Create or update a namespace

The /namespaces/:namespace API endpoint provides HTTP PUT access to create or update specific Sensu namespaces, by namespace name.

Example

In the following example, an HTTP PUT request is submitted to the /namespaces/:namespace API endpoint to create the namespace development. The request returns a successful HTTP 201 Created response.

curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
  "name": "development"
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/namespaces/development

HTTP/1.1 201 Created

API Specification

/namespaces/:namespace (PUT)
description Creates or updates a Sensu namespace.
example URL http://hostname:8080/api/core/v2/namespaces/development
payload
{
  "name": "development"
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

Delete a namespace

The /namespaces/:namespace API endpoint provides HTTP DELETE access to delete a namespace from Sensu (specified by the namespace name).

Example

The following example shows a request to the /namespaces/:namespace API endpoint to delete the namespace development, resulting in a successful HTTP 204 No Content response.

curl -X DELETE \
http://127.0.0.1:8080/api/core/v2/namespaces/development \
-H "Authorization: Key $SENSU_API_KEY"

HTTP/1.1 204 No Content

API Specification

/namespaces/:namespace (DELETE)
description Removes the specified namespace from Sensu.
example url http://hostname:8080/api/core/v2/namespaces/development
response codes
  • Success: 204 (No Content)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)

Get all namespaces for a specific user

The /user-namespaces API endpoint provides HTTP GET access to the namespaces the user has access to.

Example

The following example demonstrates a request to the /user-namespaces API endpoint, resulting in a JSON array that contains the namespaces the user has access to.

curl -X GET \
http://127.0.0.1:8080/api/enterprise/user-namespaces \
-H "Authorization: Key $SENSU_API_KEY"

HTTP/1.1 200 OK
[
  {
    "name": "default"
  },
  {
    "name": "development"
  }
]

API Specification

/user-namespaces (GET)
description Returns the list of namespaces a user has access to.
example url http://hostname:8080/api/enterprise/user-namespaces
response type Array
response codes
  • Success: 200 (OK)
  • Error: 500 (Internal Server Error)
output
[
  {
    "name": "default"
  },
  {
    "name": "development"
  }
]