> 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/query-data-gcql/query-events.md).

# Query Kubernetes Events

Search and aggregate Kubernetes events over HTTP using gcQL queries - surface warnings, group events by reason, and track cluster activity.

### Endpoint

**POST** `/api/k8s/v2/events/search`

### Authentication

This endpoint requires API Key authentication via the Authorization header.

### Headers

| Header          | Required                        | Description                                                                                                                                                         |
| --------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Authorization` | Yes                             | Bearer token with your API key                                                                                                                                      |
| `Content-Type`  | Yes                             | Must be `application/json`                                                                                                                                          |
| `X-Backend-Id`  | Only for multi-backend accounts | Your backend identifier, found under **Settings → Access → API Keys** ([details](/reference/remote-access-and-apis/api-examples/query-data-gcql.md#authentication)) |

### Request Body

| Parameter | Type   | Required | Description                                  |
| --------- | ------ | -------- | -------------------------------------------- |
| `start`   | string | Yes      | Start of the time range (RFC3339 / ISO 8601) |
| `end`     | string | Yes      | End of the time range (RFC3339 / ISO 8601)   |
| `query`   | string | Yes      | The gcQL query to execute                    |

### Examples

#### Recent Warning Events

Fetch the latest Warning-type events:

```bash
curl 'https://api.groundcover.com/api/k8s/v2/events/search' \
  -H 'authorization: Bearer <YOUR_API_KEY>' \
  -H 'content-type: application/json' \
  --data-raw '{
    "start": "2026-08-22T14:00:00Z",
    "end": "2026-08-22T15:00:00Z",
    "query": "type:Warning | sort by (_time desc) | fields _time, reason, entity_workload, message | limit 20"
  }'
```

**Example Response:**

```json
[
  {
    "_time": "2026-08-22T14:04:09.000000000Z",
    "reason": "BackOff",
    "entity_workload": "payment-service",
    "message": "Back-off restarting failed container"
  },
  {
    "_time": "2026-08-22T14:03:51.312814000Z",
    "reason": "FailedScheduling",
    "entity_workload": "checkout-service",
    "message": "0/7 nodes are available: 4 Insufficient cpu."
  }
]
```

#### Events by Reason

Count events grouped by reason to see what dominates cluster activity:

```bash
curl 'https://api.groundcover.com/api/k8s/v2/events/search' \
  -H 'authorization: Bearer <YOUR_API_KEY>' \
  -H 'content-type: application/json' \
  --data-raw '{
    "start": "2026-08-22T14:00:00Z",
    "end": "2026-08-22T15:00:00Z",
    "query": "* | stats by (reason) count() as events | sort by (events desc) | limit 10"
  }'
```

**Example Response:**

```json
[
  { "reason": "BackOff", "events": 43229 },
  { "reason": "FailedScheduling", "events": 12417 },
  { "reason": "Unhealthy", "events": 8203 }
]
```

#### Filtering by Specific Reasons

Match several reasons at once with `in()`:

```bash
curl 'https://api.groundcover.com/api/k8s/v2/events/search' \
  -H 'authorization: Bearer <YOUR_API_KEY>' \
  -H 'content-type: application/json' \
  --data-raw '{
    "start": "2026-08-22T14:00:00Z",
    "end": "2026-08-22T15:00:00Z",
    "query": "reason:in(OOMKilling, BackOff, FailedScheduling) | fields _time, reason, entity_workload, message | limit 20"
  }'
```

### Best Practices

1. **Start from `type:Warning`** when hunting for problems - normal events usually dominate the volume.
2. **Group by `reason`** to get a quick picture before drilling into raw events.
3. **Discover field names** with a `* | field_names` query if you are unsure what is available to filter on.
4. **Always bound results** with `| limit N`.


---

# 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 dynamically 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/query-data-gcql/query-events.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 `build a script that syncs our docs to a CMS` 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.
