> For the complete documentation index, see [llms.txt](https://docs.groundcover.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/list-namespaces.md).

# List Namespaces

Retrieve a list of Kubernetes namespaces within a specified time range.

### Endpoint

```
POST /api/k8s/v2/namespaces/list
```

### Authentication

This endpoint requires API Key authentication via the Authorization header.

### Headers

| Header          | Required                        | Description                    |
| --------------- | ------------------------------- | ------------------------------ |
| `Authorization` | Yes                             | Bearer token with your API key |
| `X-Backend-Id`  | Only for multi-backend accounts | Your backend identifier        |
| `Content-Type`  | Yes                             | Must be `application/json`     |
| `Accept`        | Yes                             | Must be `application/json`     |

### Request Body

| Parameter | Type   | Required | Description                                          |
| --------- | ------ | -------- | ---------------------------------------------------- |
| `sources` | Array  | No       | Filter by data sources (empty array for all sources) |
| `start`   | String | Yes      | Start timestamp in ISO 8601 format (UTC)             |
| `end`     | String | Yes      | End timestamp in ISO 8601 format (UTC)               |

#### Time Range Parameters

* **Format**: ISO 8601 format with milliseconds: `YYYY-MM-DDTHH:mm:ss.sssZ`
* **Timezone**: All timestamps must be in UTC (denoted by 'Z' suffix)

### Response

The response contains an array of namespaces for the specified time period.

#### Response Fields

| Field        | Type  | Description                                   |
| ------------ | ----- | --------------------------------------------- |
| `namespaces` | Array | Array of namespace names or namespace objects |

### Examples

#### Basic Request

```bash
curl 'https://api.groundcover.com/api/k8s/v2/namespaces/list' \
  -H 'accept: application/json' \
  -H 'authorization: Bearer <YOUR_API_KEY>' \
  -H 'content-type: application/json' \
  -H 'X-Backend-Id: <YOUR_BACKEND_ID>' \
  --data-raw '{"sources":[],"start":"2025-01-24T06:00:00.000Z","end":"2025-01-24T08:00:00.000Z"}'
```

#### Response Example

```json
{
  "namespaces": [
    "groundcover",
    "monitoring",
    "kube-system",
    "default"
  ]
}
```

### Time Range Usage

#### Last 24 Hours

```bash
# Get current time and subtract 24 hours for start time
start_time=$(date -u -v-24H '+%Y-%m-%dT%H:%M:%S.000Z')
end_time=$(date -u '+%Y-%m-%dT%H:%M:%S.000Z')

curl 'https://api.groundcover.com/api/k8s/v2/namespaces/list' \
  -H 'accept: application/json' \
  -H 'authorization: Bearer <YOUR_API_KEY>' \
  -H 'content-type: application/json' \
  -H 'X-Backend-Id: <YOUR_BACKEND_ID>' \
  --data-raw "{\"sources\":[],\"start\":\"$start_time\",\"end\":\"$end_time\"}"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/list-namespaces.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
