# List Namespaces

### 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`  | Yes      | 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\"}"
```
