# Query Vision Events

Query vision events with filters, time ranges, and pagination.

## Single Page Query

Use `query_vision_events()` to fetch a single page of results:

```python
import roboflow

roboflow.login()

rf = roboflow.Roboflow()
ws = rf.workspace()

page = ws.query_vision_events(
    "a1b3c8e1",                          # use case ID (required)
    event_type="quality_check",          # filter by single event type
    start_time="2024-01-14T00:00:00Z",   # ISO 8601 start time
    end_time="2024-01-15T23:59:59Z",     # ISO 8601 end time
    limit=50,                            # max events per page
)

for evt in page["events"]:
    print(evt["eventId"], evt["eventData"])
```

You can also pass additional filters as keyword arguments. These are forwarded directly to the API:

```python
page = ws.query_vision_events(
    "a1b3c8e1",
    event_types=["quality_check", "safety_alert"],
    deviceId={"operator": "eq", "value": "camera-node-5"},
    customMetadataFilters=[
        {"field": "temperature", "operator": "gt", "value": 70, "type": "number"}
    ],
    eventFieldFilters=[
        {"column": "result", "operator": "eq", "value": "fail"}
    ],
)
```

For manual pagination, use the `cursor` parameter with the `nextCursor` value from a previous response:

```python
all_events = []
page = ws.query_vision_events("a1b3c8e1", limit=100)
all_events.extend(page.get("events", []))

while page.get("hasMore"):
    page = ws.query_vision_events("a1b3c8e1", cursor=page["nextCursor"], limit=100)
    all_events.extend(page.get("events", []))
```

## Paginate Through All Results

Use `query_all_vision_events()` to automatically paginate through all matching events. It yields one page of events at a time:

```python
all_events = []

for page in ws.query_all_vision_events(
    "a1b3c8e1",
    event_type="quality_check",
    start_time="2024-01-14T00:00:00Z",
    end_time="2024-01-15T23:59:59Z",
):
    all_events.extend(page)

print(f"Found {len(all_events)} events")
```

For full details on available filters, operators, and response formats, see the [REST API reference](/developer/rest-api/vision-events/query-vision-events.md).


---

# Agent Instructions: 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 current page URL with the `ask` query parameter:

```
GET https://docs.roboflow.com/developer/python-sdk/vision-events/query-vision-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
