> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getlurk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Views

> Saved questions about your project: a number, a chart over time or a ranked list, read from your server by key.

A **view** is a saved question about your project: "How many people came back this week?", "Beans given each day", "The top 10 regulars". Lurk answers it from your project's data each time you read it. Your server reads it and shows the answer in your site, app or bot. Dashboards are views laid out on a grid.

A view is typed data, never SQL. It has four parts:

| Part | What it says | Values |
| - | - | - |
| `who` | Whose data | `"everyone"`, or `{ "audience": "regulars" }` (an audience's key or `aud_…` ID) |
| `what` | What to count, one to four measures | `active_users`, `returning_users`, `new_users`, `events` (one event or all), and per unit `given`, `spent`, `held` |
| `over` | The range | `now`, `today`, `this_week`, `last_week`, `last_7_days`, `last_14_days`, `last_30_days`, `last_90_days`, `this_month`, `all_time` |
| `shape` | How the answer comes back | `number`, `over_time` (every `day`, `week` or `month`) or `list` (a ranked list) |

Ranges and weeks follow your project's time zone, and a week is Monday to Sunday.

## Save a view

`POST /v1/views` with a name and a definition. The `name` is 1 to 80 characters and the optional `description` up to 280. The `key` is optional, defaults to a slug of the name (`view-` goes in front when a digit leads: "7 day actives" is `view-7-day-actives`), and must not be taken by another view in the project: lowercase words joined by dashes, starting with a letter, up to 64 characters; a taken key is refused with `validation_failed`. The audience and the units it names must exist.

```bash theme={null}
curl https://api.getlurk.com/v1/views \
  -H "Authorization: Bearer $LURK_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: top-earners-1" \
  -d '{
    "name": "Top earners this week",
    "key": "top-earners",
    "definition": {
      "who": "everyone",
      "what": [{ "measure": "given", "unit": "beans" }],
      "over": "this_week",
      "shape": { "type": "list", "by": "user", "size": 10 }
    }
  }'
```

A view only reads, so a project key, an agent or a person in the dashboard (other than a viewer) can save one, with no approval.

## Read a view

`GET /v1/views/{id}` takes the view's `view_…` ID or its key, and answers with the view and its `answer`. Read it from your server: the key never goes in browser code.

```bash theme={null}
curl https://api.getlurk.com/v1/views/top-earners \
  -H "Authorization: Bearer $LURK_KEY"
```

Three query parameters change one read without changing the view:

* `range`: read over another range, such as `?range=last_30_days`.
* `compare`: `?compare=true` also answers for the span of the same length just before, for "up 12% on last week".
* `audience`: read for another audience than the view's `who`.

The answer always has the same fields. Which ones carry data depends on the shape:

```json theme={null}
{
  "period": { "from": "2026-11-02T00:00:00.000Z", "to": "2026-11-09T00:00:00.000Z" },
  "compared_with": null,
  "series": [{ "measure": { "measure": "given", "unit": "beans" }, "unit": "beans", "total": 4820, "previous_total": null, "points": [], "previous_points": [] }],
  "rows": [{ "rank": 1, "label": "u_30be", "user": { "id": "usr_…", "external_id": "u_30be" }, "rule": null, "property": null, "value": 310, "previous_rank": null, "values": [310] }],
  "total_rows": 184,
  "computed_at": "2026-11-06T09:00:00.000Z"
}
```

* **`number`**: each measure is one `series` entry, and its `total` is the answer.
* **`over_time`**: each `series` entry also has `points`, one per day, week or month inside the range.
* **`list`**: `rows` holds the ranking, with `value` for the first measure and `values` for each. `total_rows` says how many rows there are in all.

With `compare`, `previous_total`, `previous_points` and `previous_rank` are filled in, and `compared_with` names the span before.

## Preview a view

`POST /v1/views/preview` answers a `definition` (and `compare`) without saving it, over a range with a start, never all time. For a funnel, its answer adds `steps`.

A funnel is a preview-only shape: `{ "type": "funnel", "steps": [...], "within": "1d" }`, and `what` is `[{ "measure": "active_users" }]`. Each step is an event, with an optional `where`. `people` took a step and every one before, in order; `median_seconds` is the typical time from the step before.

How a person is counted:

* Each person has one try, from their first step one in the range. A later try is not counted.
* Each later step comes strictly after the one before, at most `within` after step one (that moment included, even past the range).
* A visitor who signs in is one person, through their aliases.

The last step can be `{ "reward": "first" }`: a person's first units from a rule or by hand (not starting units, passes, sends or undone rewards; held units count when given). A reward from the step's own event is 0 seconds after it. Only the first reward is read: if it came before the step before, the person is not counted.

A funnel cannot be saved as a view yet.

## What each measure counts

* `events`: events that happened in the range. Leave out `event` to count every event.
* `active_users`: people with at least one event in the range, each counted once.
* `new_users`: people Lurk first heard of in the range.
* `returning_users`: active people Lurk first heard of before the range began.
* `given`: what was added to a unit in the range, by rules, by hand or by an undo. `spent` is what was taken, as a positive number.
* `held`: what everyone holds of a unit at the end of the range. `now` is only for `held`, as a number or a ranked list of people.

By default a view counts events from your own server, never a device's: the same as a [rule](https://docs.getlurk.com/rules.md) with no `source`. Set `definition.source` to `trusted` (your server only) or `any` (a device's too). `given`, `spent`, `held` and `new_users` count whatever `source` says.

## Ranked lists

A `list` ranks people (`by: "user"`), rules (`by: "rule"`) or the values of one property of an event (`by: "property"`), up to `size` rows (at most 100).

* People can be ranked by `events`, `given`, `spent` or `held`.
* Rules can be ranked by `given` or `spent`.
* A list by property names its `property` and counts one named event. A value that looks personal, such as an email address or a link, is counted under one row, Hidden. It is a best-effort check, not a guarantee.

## List and change views

* `GET /v1/views` lists the project's views, newest first. `search` matches part of a name or key, and `conversion=true` keeps only conversions. Lists come a page at a time ([Pagination](https://docs.getlurk.com/guides/pagination.md)).
* `PATCH /v1/views/{id}` renames a view, changes its description (`null` removes it) or replaces its whole definition. Send at least one of them. Dashboards that show it show the new question.

## Conversions

A conversion is a view marked `conversion: true`: something you want people to do. Only a view that counts one named event can be one. Set it with `conversion` on `POST /v1/views` or `PATCH /v1/views/{id}`. At the project's limit, turn one off first.

Only an owner, admin or developer, or a project key, can mark a conversion, clear the mark, or change a marked view.

Agents reach the same operations through the [MCP server](https://docs.getlurk.com/mcp-server.md). Every view also lists its `endpoint` (`/v1/views/top-earners`) and the dashboards that show it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.