# Query collection rows (one table)

> Source: https://elaichi.ai/docs/api-reference/collections/collection/querycollectionrowsintable/

`POST /collection/{id}/table/{tableKey}/rows/query`

Resource: **Collection** · API: **Collections**

## Path parameters

- **`id`** _(string, required)_
  Resource id
- **`tableKey`** _(string, required)_
  Table key; `main` is the default table.

## Request body

- **`filter`** _(unknown)_
- **`q`** _(string)_
- **`sort`** _(array<unknown>)_
- **`fields`** _(array<string>)_
- **`limit`** _(integer)_
- **`cursor`** _(string)_
- **`group`** _(object, required)_
  Only the rows of one group: the rows an aggregate group_by [{ field, bucket }] counts under the key value. field is a select, text, email, url, user, boolean, date or datetime field (400 validation_error, details.field "group.field", for number, long_text, json, multi_select or a system field). A date or datetime field needs bucket and refuses none; every other type refuses one (details.field "group.bucket"). value is the key the aggregate returned: "2026-10-05" for day, the Monday "2026-10-05" for week, "2026-10" for month (UTC), 1 or 0 (true/false also accepted) for boolean. value null (or empty) is the empty group. total_count is null when set. 400 field_protected on a protected field below edit.
  - **`field`** _(string)_
  - **`bucket`** _(string)_
    Allowed: `day`, `week`, `month`
  - **`value`** _(string,number,boolean,null)_

## Response body

- **`result`** _(array<object>)_
  - **`id`** _(string)_
  - **`fields`** _(object)_
  - **`created_at`** _(string)_
  - **`updated_at`** _(string)_
  - **`created_by`** _(string,null)_
  - **`updated_by`** _(string,null)_
- **`next_cursor`** _(string,null)_
- **`prev_cursor`** _(string,null)_
- **`total_count`** _(integer,null)_
- **`row_visibility`** _(string)_
- **`users`** _(unknown)_

## Code examples

### curl

```bash
curl -X POST 'https://api.elaichi.ai/collection/<id>/table/<tableKey>/rows/query' \
  -H 'Authorization: Bearer $ELAICHI_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"q":"your_q","sort":[],"fields":[],"limit":0,"cursor":"your_cursor","group":{}}'
```

### JavaScript

```javascript
const body = {
  "q": "your_q",
  "sort": [],
  "fields": [],
  "limit": 0,
  "cursor": "your_cursor",
  "group": {}
};

const response = await fetch('https://api.elaichi.ai/collection/<id>/table/<tableKey>/rows/query', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ' + process.env.ELAICHI_API_TOKEN,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import os
import requests

url = "https://api.elaichi.ai/collection/<id>/table/<tableKey>/rows/query"
headers = {
    "Authorization": f"Bearer {os.environ['ELAICHI_API_TOKEN']}",
    "Content-Type": "application/json",
}
payload = {
    "q": "your_q",
    "sort": [],
    "fields": [],
    "limit": 0,
    "cursor": "your_cursor",
    "group": {}
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```
