# Read a view's groups (/build/view-groups)

Ask the server for each group of a saved view and how many items it holds, to draw a grouped view without reading every item.



An app that draws a grouped [view](/build/views), such as a board with a count on each column, needs every group and how many items it holds. **The server counts them in one request,** so the app doesn't read every item to count. **You need** a credential that reads `system.view`, and the ID of a view.

## Ask for the groups [#ask-for-the-groups]

[List a view's groups](/reference/api/views/listViewGroups) takes the view's ID. This asks for the groups of the view [Save and read a view](/build/views#create-a-view) made, which groups photos by month. In the TypeScript example, `marfa` is a [TypeScript SDK client](/reference/typescript-sdk#create-a-client).



**CLI**

```bash  
marfa views groups <view-id> --time-zone Europe/Lisbon
```

**HTTP**

```http
GET /views/<view-id>/groups?time_zone=Europe/Lisbon
Authorization: Bearer <key>
```

**TypeScript**

```ts
const { data } = await marfa.GET("/views/{id}/groups", {
  params: { path: { id: viewId }, query: { time_zone: "Europe/Lisbon" } },
});
```

The answer names each group by its `key`, with the `count` of items in it:

```json
{
  "groups": [
    { "key": "2026-10-01", "count": 2 },
    { "key": "2026-11-01", "count": 1 }
  ]
}
```

**`time_zone` is the IANA time zone that dates are put into periods in.** Leave it out and the server uses UTC. A name that isn't an IANA time zone is refused `400 validation_error`.

## What the answer holds [#what-the-answer-holds]

* **The items are the ones [List a view's items](/reference/api/views/listViewItems) lists to the same credential,** and no others. That listing ignores the view's `group`, so read the groups here and the items there.
* **The groups come in the view's group order,** with those its `group.order` names first, and without those its `group.hidden` names.
* **The null group has the `key` `null`.** A view with no `group.by` that lists at least one item answers that one group, holding every item.
* **A view that lists nothing answers an empty list.**

[Group the items](/build/views#group-the-items) says which groups each `group` setting makes.

## Groups by an edge [#groups-by-an-edge]

A view grouped by `edge[<type>]` or `backref[<type>]` has one group for each item linked, and the group's `key` is that item's ID.

* **`edge[<type>]` counts every edge of that type from a listed item,** under the item it points to, even when the credential can't read that item's type.
* **`backref[<type>]` leaves out an edge whose from item the credential can't read,** or that its source filter hides.
* **A credential that can't read the edge type** is refused `403 edge_type_not_permitted`.

## When the groups are refused [#when-the-groups-are-refused]

| When | The answer |
| - | - |
| The view lists more than 100,000 items to the credential | `400 validation_error` naming `group`. Narrow the view's `query`. |
| The view has more than 1,000 groups, once its hidden groups are left out | `400 validation_error` naming `group.by` |
| List a view's items refuses the view with a `400` or a `403` | The same status and code |
| No view the credential can read has the ID | `404 item_not_found` |

## From an agent or a working copy [#from-an-agent-or-a-working-copy]

* **Over MCP,** `marfa_get` takes one view's ID with `groups: true`, and `time_zone` if you need one. It answers the view's `id` and its `groups`. An answer past 40,000 characters leaves out the last groups, and `left_out` says how many.
* **`groups` goes alone.** With more than one ID, with `edges` or `file_link`, or with `field` or `offset`, the call is refused `validation_error`. So is a `time_zone` sent without `groups`.
* **A [working copy](/build/write-in-a-working-copy#read-from-the-copy)** answers the same groups with no connection: `marfa device views groups`.

The rules are in the contract's views chapter, under [Reading a view's groups](https://github.com/withmarfa/marfa/blob/main/conformance/spec/views.md#reading-a-views-groups).
