# Summarize collection rows

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

`POST /collection/{id}/aggregate`

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

## Path parameters

- **`id`** _(string, required)_
  Resource id

## Request body

- **`group_by`** _(array<object>)_
  A text or select group puts NULL and the empty string in one group whose key is null.
  - **`field`** _(string)_
  - **`bucket`** _(string)_
    Allowed: `day`, `week`, `month`, `quarter`, `year`
  - **`order`** _(string)_
    "choices" (select fields only, 400 on any other): groups come in the field's declared choice order, then values that are no longer choices (alphabetical), then the empty group. "value" (any field): by the key, the empty group last in both directions; sort { by: <this field>, direction } sets the direction. Absent: by key, ascending unless sort says otherwise, with the empty group sorting as the lowest key.
    Allowed: `choices`, `value`
- **`metrics`** _(array<unknown>)_
- **`filter`** _(unknown)_
- **`q`** _(string)_
- **`sort`** _(unknown)_
- **`limit`** _(integer)_
- **`cursor`** _(string)_

## Response body

- **`result`** _(array<unknown>)_
- **`next_cursor`** _(string,null)_
- **`prev_cursor`** _(string,null)_
- **`total_groups`** _(integer)_
- **`row_visibility`** _(string)_
- **`users`** _(unknown)_

## Code examples

### curl

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

### JavaScript

```javascript
const body = {
  "group_by": [],
  "metrics": [],
  "q": "your_q",
  "limit": 0,
  "cursor": "your_cursor"
};

const response = await fetch('https://api.elaichi.ai/collection/<id>/aggregate', {
  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>/aggregate"
headers = {
    "Authorization": f"Bearer {os.environ['ELAICHI_API_TOKEN']}",
    "Content-Type": "application/json",
}
payload = {
    "group_by": [],
    "metrics": [],
    "q": "your_q",
    "limit": 0,
    "cursor": "your_cursor"
}

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