# Query data

`Query*` endpoints all accept `filter_conditions`, `sort`, and `limit` in the request body. Pass the body as JSON with `--request`. The same shape works for every `Query*` endpoint across every product.

To see the exact body an endpoint accepts, print its schema:

```bash
getstream api QueryChannels --schema
```

The recipes below assume you already know the operator vocabulary. See the [filter operators reference](https://getstream.io/cli/docs/reference/filter-operators/) for the full list.

## Top N channels by activity

```bash
getstream api QueryChannels --request '{
  "filter_conditions": { "member_count": { "$gte": 10 } },
  "sort":              [{ "field": "last_message_at", "direction": -1 }],
  "limit":             10
}'
```

## Unreviewed flagged messages

```bash
getstream api QueryMessageFlags --request '{
  "filter_conditions": { "is_reviewed": false },
  "sort":              [{ "field": "created_at", "direction": -1 }],
  "limit":             20
}'
```

## Admins matching a name prefix

```bash
getstream api QueryUsers --request '{
  "filter_conditions": {
    "$and": [
      { "role": "admin" },
      { "name": { "$autocomplete": "ali" } }
    ]
  },
  "limit": 25
}'
```

## Active calls

```bash
getstream api QueryCalls --request '{
  "filter_conditions": { "ongoing": true },
  "limit":             20
}'
```

## Channels a specific user belongs to

```bash
getstream api QueryChannels --request '{
  "filter_conditions": {
    "$and": [
      { "type":    "messaging" },
      { "members": { "$in": ["alice"] } }
    ]
  },
  "limit": 30
}'
```

## Count matches in a page

```bash
getstream api QueryChannels --request '{"limit":30}' --jq '.channels | length'
```

QueryChannels returns at most 30 channels per page, so this counts one page; advance with `offset` or the `next` cursor for a larger total. See the [jq expressions reference](https://getstream.io/cli/docs/reference/jq/) for more expressions.

## Body from a file

For queries that grow past one screen, keep them in a file and expand it into `--request`:

```bash
getstream api QueryChannels --request "$(cat query.json)"
```

## Non-`Query*` endpoints

Path parameters are always flags (`--id`, `--type`); the request body goes through `--request`. `Get*` and `Delete*` are mostly path flags, while `Create*` and `Update*` take a body and still pass any path parameters as flags. Run `--help` for an endpoint's flags or `--schema` for the full body:

```bash
getstream api UpdateChannel --schema
```

## Related

- [Filter operators reference](https://getstream.io/cli/docs/reference/filter-operators/): the operator vocabulary
- [Endpoint naming](https://getstream.io/cli/docs/reference/endpoints/): the catalog and how names are organized
- [`getstream api` reference](https://getstream.io/cli/docs/commands/api/): every flag and option

---

For the most recent version of this documentation, visit [https://getstream.io/cli/docs/query-data/](https://getstream.io/cli/docs/query-data/).