# Sources

A page can fetch its own data. Give it named `sources`, and Legato calls each one on a schedule and fills the cards from the answer. You don't need to write Swift, change the app or keep an agent running: once the page is written, it stays current by itself.

A source can be an internet API such as GitHub or Tessie, a service on your network such as Pi-hole or Home Assistant, or this Mac's own [calendars and reminders](https://legatobar.com/docs/source-calendar.md). Cards on a page with sources can also carry [buttons](https://legatobar.com/docs/buttons.md) that call the same service: pause ad blocking, lock the car, tick off a task. The page files, the answers and your [secrets](https://legatobar.com/docs/secrets.md) stay on the Mac; requests go only to the services the page names.

An agent can write a page like this as easily as one with fixed values: ask it for a page that keeps itself up to date. A page can mix both, sourced cards next to cards with values written in.

## Start here

- [Try an API and preview](https://legatobar.com/docs/source-preview.md): A whole page that reads a public API with no key, and a way to see a source's answer before it starts polling.
- [Worked examples](https://legatobar.com/docs/source-examples.md): Pages to copy from, including a feed and a service that takes several requests.

## Set up a source

- [Source fields and loading](https://legatobar.com/docs/source-reference.md): Every field of a source and of a card's `source`, and which APIs fit.
- [Signing in and requests](https://legatobar.com/docs/source-requests.md): How the secret reaches the service, and the methods, bodies and answer formats a source can use.
- [Secrets](https://legatobar.com/docs/secrets.md): API keys in the Mac's Keychain or 1Password, each tied to one host.
- [Polling and failures](https://legatobar.com/docs/source-polling.md): When a source refreshes, what its cards show when a fetch fails, and how it backs off.
- [Calendar and Reminders](https://legatobar.com/docs/source-calendar.md): This Mac's events and tasks as sources, with no API at all.
- [Troubleshooting](https://legatobar.com/docs/source-troubleshooting.md): What to check when a page is missing or a card shows an error.

## Use the answer

- [Mapping](https://legatobar.com/docs/mapping.md): Paths and rules that take fields from an answer and put them in a card.
- [Buttons](https://legatobar.com/docs/buttons.md): Send something back to the service from a card.


---

# Try an API and preview

## Try a public API

This complete page uses [GitHub’s Get a repository endpoint](https://docs.github.com/en/rest/repos/repos#get-a-repository) to show stars and forks for a public repository. It needs no API key.

1. Open Legato. Each time it starts, it installs the page schema in its Pages folder for editor suggestions.
2. [Download github-starter.json](https://legatobar.com/examples/github-starter.json), or copy the complete JSON below. Save it as `~/Library/Application Support/Legato/Pages/github-starter.json`, using plain text with the `.json` extension. Or, from Terminal: `/Applications/Legato.app/Contents/Helpers/legato set github-starter github-starter.json`.
3. Within a second, Legato finds the file and the **GitHub** page appears. The first fetch fills both cards.

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "GitHub",
  "sources": {
    "repo": {
      "url": "https://api.github.com/repos/octocat/Hello-World",
      "auth": { "type": "none" },
      "headers": {
        "Accept": "application/vnd.github+json",
        "X-GitHub-Api-Version": "2026-03-10"
      },
      "every": "1h"
    }
  },
  "cards": [
    { "id": "stars", "type": "stat", "label": "Stars",
      "source": { "ref": "repo",
                  "map": { "value": "stargazers_count" } } },
    { "id": "forks", "type": "stat", "label": "Forks",
      "source": { "ref": "repo",
                  "map": { "value": "forks_count" } } }
  ]
}
```

The page then makes **one request per hour while your Mac is awake and unlocked**. Both cards use the same answer: `sources.repo` defines the connection, `ref` selects it, and each `map` takes a different response field. After sleep or unlock, a due source refreshes; opening the panel also checks sources that are due.

Change `octocat/Hello-World` to another public `owner/repository`, or follow the next section to connect a different API. [GitHub](https://legatobar.com/services/github) has the full pages, with a token. Save the file again and the page changes within a second. Right-click a page and choose **Show in Finder** to find its file, or **Delete Page…** to move the file to the Trash (put it back from there to restore it).

## Edit with suggestions

Start from a JSON page and let the editor guide the fields. Open the page in VS Code or another editor with JSON Schema support. The starter's `$schema` line points to `./.schemas/page.schema.json`, which Legato installs in the `.schemas` directory inside Pages. It enables property suggestions, hover descriptions and structural validation without needing an internet connection.

Keep that line when adapting an example. The schema covers sources, authentication, mappings, buttons and card fields. It can catch an invalid field or missing property; it cannot know an API's real response or prove that a mapping selects the right data. Use the preview below to check source references, mappings and rendered cards.

Both the schema and the app reject unknown top-level page keys, including `widgets` and `light`. They also reject unknown keys in sources, authentication, requests, conditions and buttons. The app still ignores unknown options inside mapping rules, such as `defualt`; the schema catches those too.

Keep the `$schema` line to catch typos while editing. If you keep pages elsewhere, [download the schema](https://legatobar.com/schemas/page.schema.json) and place it at the same relative path, or adjust `$schema` to its location.

## Preview before polling

Before a page polls, check its cards in the **Source Preview** window, with a sample response or one real fetch. Right-click a page in the panel's sidebar and choose **Preview Source…** to open it on that page's file.

For a file that isn't in the Pages folder yet, right-click an empty part of the sidebar, choose **Source Preview…**, then **Choose page…**.

Then select a named **Source**. Loading a file makes an in-memory preview; it does not change the file or add it to your active pages.

Paste a **Sample response**, or use **Import…** to load a UTF-8 response file, then click **Preview sample**. For the GitHub starter, this illustrative sample is enough:

```json
{ "stargazers_count": 100, "forks_count": 12 }
```

The preview displays the actual cards, mapping issues, **Mapped card JSON**, and **Response and derived values**. Sample previews require an active trial or license. They do not contact an API or read source secrets. They help catch missing response fields or values that do not fit a card, beyond what editor validation can check.

For a direct request to the source’s `url`, paste its raw JSON, text or Prometheus answer. If the source uses named `requests`, even just one, paste a JSON object keyed by request name; encode text and Prometheus answers as JSON strings. Samples and imported pages must be no larger than 1 MB.

To try the real service, click **Fetch Once**; it works during the trial or with a [license](https://legatobar.com/docs/license.md). It uses the selected source and its saved Keychain secret through the same fetcher as normal polling, including shared rate-limit waits and conditional GETs. Preview cards do not run buttons. **Cancel** stops a pending preview fetch; changing the source or sample clears the old result.

An agent gets the same sample preview with the MCP tool [`preview_page`](https://legatobar.com/docs/mcp-tools.md#checking-a-pages-sources), or `legato preview` from a script, and sees each source's last fetch in `get_page`'s `status.sources`.

Edit configuration in your external editor, then click **Reload page**. Reloading clears the old output and keeps your selected source and sample when that source still exists. To use it in the menu bar, save it in the Pages folder. **Open Pages Folder** in the editor-support section opens that location and installs the bundled schema if needed.

## Adapt a request you already know

Start with a working API request and a sample response. For the starter above, the equivalent request is:

```sh
curl 'https://api.github.com/repos/octocat/Hello-World' \
  -H 'Accept: application/vnd.github+json' \
  -H 'X-GitHub-Api-Version: 2026-03-10'
```

A polling source should read data. Use POST polling only for read operations, such as a template request; put commands that change something in [Buttons](https://legatobar.com/docs/buttons.md#buttons), which run when clicked.

Translate the parts you need into a named source:

| Request part | Page setting |
| --- | --- |
| URL | `sources.<name>.url` |
| GET or POST | `method`; GET is the default |
| JSON sent with POST | `body`, as a JSON value, not a quoted curl command |
| Accept, API version, other non-secret headers | `headers`, an object of header names and string values |
| API token or password | `secret` names an item you save in **Settings → Secrets** (or with [`Legato secret set`](https://legatobar.com/docs/secrets.md#from-the-command-line-or-an-agent)); `auth` describes how to send it |
| Fields in the response | Card `source.map`, such as `"value": "stargazers_count"` |
| How often it should refresh | Source `every`; start conservatively, such as `1h` |

For a bearer token, set `"secret": "my-api"` and `"auth": { "type": "bearer" }`, then save `my-api` for the API's host in Settings → Secrets. Keep the credential itself out of the file. Use `auth: { "type": "none" }` for an unauthenticated endpoint.

Every request sends `Accept: application/json` and `User-Agent: Legato`, unless the source's headers set their own. Source `headers` apply to its data requests and buttons. A named request or button can override a common header; authentication fills the credential header afterward. A login's own headers belong in `auth.request.headers` and are separate from these common headers. See [Signing in](https://legatobar.com/docs/source-requests.md#signing-in) for API-key headers, Basic authentication and token logins.

Start with one card and one field. Add more cards referencing the same source after that works. The [card reference](https://legatobar.com/docs/cards.md) lists the fields each card accepts, and [Mapping](https://legatobar.com/docs/mapping.md#mapping) explains nested objects, arrays and small transformations.



---

# Source fields and loading

## Loading and status files

Legato loads a page within a second of a save, and a script can wait for `Pages/.status/<id>.json` to say whether it took it; `legato set` and the MCP `set_page` tool do that for you. They check the page before writing it, so a page with a mistake leaves the old one as it was. [How Legato loads a page](https://legatobar.com/docs/page-loading.md#how-legato-loads-a-page) and [Status files](https://legatobar.com/docs/page-loading.md#status-files) have the details.

A status's `ok` describes the page as a whole. A card whose `source` or buttons are wrong still loads as a warning card of its own, saying what's wrong; check it in the panel or with **Preview Source…** on the page's right-click menu.

## Source and page reference

Each file is one page: `title`, optional `icon`, up to 24 `cards`, named `sources`, and an optional [`notify`](https://legatobar.com/docs/source-reference.md#notifications) and [`title_from`](https://legatobar.com/docs/detail-pages.md#titled-by-its-item); see [Writing and versions](https://legatobar.com/docs/page-writing.md) for the rest. Any other top-level key stops the file loading. The optional `$schema` property enables editor assistance; Legato still checks the page when it loads.

A page can mix sourced cards with ordinary cards whose values are written in.

A named source contains connection settings, without `map`:

| Source field | Required? | Meaning |
| --- | --- | --- |
| `kind` | no | `http` (the default), `calendar` for this Mac's own calendars, or `reminders` for its reminders; see [Calendar sources](https://legatobar.com/docs/source-calendar.md#calendar-sources) and [Reminders sources](https://legatobar.com/docs/source-calendar.md#reminders-sources). The rest of this table is for `http`. |
| `url` | yes, or `hosts` or `feeds` | API address. A source that reads every host on a list gives [`hosts`](https://legatobar.com/docs/source-requests.md#several-hosts-from-a-list) instead, and one that reads every feed on a list gives [`feeds`](https://legatobar.com/docs/source-requests.md#several-feeds-from-a-list). Use HTTPS for internet APIs; plain HTTP is intended for local services. With `requests`, its scheme, host and port define the origin. Its path or query can carry [dates](https://legatobar.com/docs/source-requests.md#dates-in-requests). |
| `secret` | no | Name in Settings → Secrets, not the credential value: 1–48 lowercase letters, digits and hyphens, such as `my-api`. |
| `secret_optional` | no | `true`: while no secret is saved for this host, requests go without signing in. For a key or password sent with each request, not a login. Mostly for [host lists](https://legatobar.com/docs/source-requests.md#several-hosts-from-a-list), where some hosts have a password and some don't. |
| `secret_expires` | no | A name for the [expiry date](https://legatobar.com/docs/secrets.md#expiry-dates) saved with `secret`, such as `token_expires`. The date (`2027-02-09`) is added to the answer under that name before `derive`, and the name is left out when no date is saved. Lowercase letters, digits and `_`; not `data`, a request's name or a derived name. |
| `auth` | no | How to authenticate. A named secret defaults to bearer authentication. |
| `method`, `body` | no | GET or POST, with an optional JSON body. Used for a single request to `url`. |
| `headers` | no | Common headers for data requests and buttons. |
| `format` | no | `json` (default), `text`, `feed`, `prometheus` or `docker-logs` for a single request. |
| `requests` | no | Up to 8 named requests, combined into one answer; paths use the source origin. |
| `derive` | no | Values computed from the answer before mapping. |
| `fail` | no | When an answer the service sent counts as a failure all the same: `{ "when": condition, "message": rule }`. See [When the answer reports an error](https://legatobar.com/docs/source-polling.md#when-the-answer-reports-an-error). |
| `collect` | no | Rows of the answer to keep on this Mac for other pages. See [History](https://legatobar.com/docs/source-reference.md#history). |
| `every` | no | Whole number plus `s`, `m`, `h` or `d`, such as `15m` or `2h`. Minimum `1m`; default `5m`. |

A source can also be `{ "dataset": "name" }`: a page's history, kept on this Mac, read for the period showing. See [History](https://legatobar.com/docs/history-reading.md#read-the-history-on-another-page).

Each sourced card has exactly these connection fields:

| Card `source` field | Required? | Meaning |
| --- | --- | --- |
| `ref` | yes | A name in the page's `sources` object. |
| `map` | yes, unless `when` is set | Card fields to fill, and their paths or rules. A card whose content is written out and only shows on a condition needs none. |
| `empty` | no | `{ "when": condition, "text": template }`. When the condition holds in the answer, the card shows the text under its own label, with its buttons hidden (Add Event buttons stay), instead of a card the answer can't fill: no meetings, no open pull requests, nothing due. |
| `when` | no | A [condition](https://legatobar.com/docs/mapping-conditions.md#conditions): the card shows only while it holds. See [Cards that show on a condition](https://legatobar.com/docs/mapping-conditions.md#cards-that-show-on-a-condition). |
| `loading` | no | On a page whose param [`selects`](https://legatobar.com/docs/detail-pages.md), what the card shows while a pick is on its way and the card reads something it changes: `placeholder` (the default) draws its last shape in grey, `keep` draws it as it was. `keep` suits a list whose length follows the pane beside it. |
| `failed` | no | On a `status` card only: `{ "state", "detail", "after" }`. Once the source has failed `after` times in a row (2 to 10, default 3), the card shows `state` (`warning`, `critical` (the default) or `unknown`) and `detail` instead of its last answer. See [When a service stops answering](https://legatobar.com/docs/source-polling.md#when-a-service-stops-answering). |

**Behind a path.** For a service behind a reverse proxy, use `"url": "https://media.example.com", "base": "/sonarr"`. Legato adds `base` before request, button, row action and row image paths, including login and `title_from` requests. Full HTTPS URLs stay unchanged. The base starts with `/` and cannot contain `?`, `#` or `..`. A trailing slash is removed.

**Self-signed certificates.** A server at an IP address or a `.local` name can use one. The first time Legato meets it, the source fails with "certificate isn't trusted", and you trust it in [Settings → Certificates](https://legatobar.com/docs/settings.md#certificates). Legato then accepts only that certificate from that address and port. A page file can't trust a certificate.

One source can fill several kinds of card from the same answer: stats, lists and status cards alike. The source owns the polling interval. All its cards share the fetch and schedule, so adding a card does not add another request, and Legato checks for updates only while your Mac is awake and unlocked. With multiple named requests, one cycle makes each request once. The [worked examples](https://legatobar.com/docs/source-examples.md#worked-examples) are complete pages; other snippets are explicitly labeled as fields or rules to place inside a page.

### Supported APIs and limits

Use direct sources for simple GET/POST APIs with JSON request bodies, JSON, text, feed or Prometheus responses, static API credentials, one login request returning a token, or an OAuth client's ID and secret. Named requests run independently, with two exceptions: a request with [`each_row`](https://legatobar.com/docs/source-requests.md#a-request-for-each-row) is sent once for each row of another request's answer, after it (and one more may be sent for each row inside those answers), and one with [`with`](https://legatobar.com/docs/source-requests.md#a-value-from-another-answer) takes a value from another request's answer, after it. There is no longer chain than that. A request with [`follow`](https://legatobar.com/docs/source-requests.md#a-list-across-pages) is one request sent again for each page of a list. A request with [`missing` or `optional`](https://legatobar.com/docs/source-requests.md#a-request-with-nothing-there-yet) is left out of the answer when it has nothing there yet or fails, instead of failing the source.

A source with **no `secret` and no `auth`** can also name a full `https://` URL in `requests`, including another host. For example, `"url": "https://api.open-meteo.com"` with `"requests": {"fc": "/v1/forecast?latitude={param.lat}&longitude={param.lon}&current=temperature_2m", "air": "https://air-quality-api.open-meteo.com/v1/air-quality?latitude={param.lat}&longitude={param.lon}&current=us_aqi"}` lets one card read `fc.current.temperature_2m` and `air.current.us_aqi`. Params are filled and percent-encoded as for paths. Full URLs must use HTTPS, cannot contain a login, and cannot have `method` or `body`; they are GET requests with the usual timeout, size limit, headers and error handling. Both hosts appear in the page’s source summary and Source Preview; rate limits belong to each destination. A source with a secret can read one such URL too, from a request with `"auth": { "type": "none" }`, which goes without the source's sign-in or headers; see [A public address beside the service](https://legatobar.com/docs/source-requests.md#a-public-address-beside-the-service).


OAuth sign-in through a browser for services other than those Legato [connects to](https://legatobar.com/docs/source-requests.md#connections) (an [OAuth client](https://legatobar.com/docs/source-requests.md#oauth-clients) is supported), cookie-based login, form or multipart bodies on reads and sign-ins ([buttons can send a form](https://legatobar.com/docs/buttons.md#buttons-that-send-a-form)), XML other than RSS and Atom feeds, automatic pagination and self-signed certificates on a host name other than a `.local` one are not supported, nor is a credential that has to go in the URL path. [Services you may already use](https://legatobar.com/docs/source-examples.md#services-you-may-already-use) lists some that fit and some that don't. For those APIs, or for complex transformations, run an agent or script separately and have it [write the finished page](https://legatobar.com/docs/page-writing.md#writing-a-page) with `legato set`. Legato does not run that script. A Home Assistant template is executed by Home Assistant, not by Legato.

Choose an interval suited to the API's quota and how quickly the information changes. An hourly public-data poll is a better starting point than the one-minute minimum. Server-requested waits can delay the next attempt; conditional GETs can avoid downloading an unchanged response, but still make a request when due.

## Notifications

A page notifies when one of its `status`, `gauge` or `fleet` cards moves up to warning or critical, whether the card's state comes from a source or is written in; see [Notifications](https://legatobar.com/docs/notifications.md). A card still waiting for its source's first answer keeps the level it had, so a page waiting on its sources doesn't count as a recovery.

A page can also send a notification of its own with `notify`:

```json
"notify": { "id": "backup-2026-10-24", "title": "Backup finished", "body": "1,204 files, 3.1 GB, in 4 minutes." }
```

- Each `id` shows once. Save the file with a new `id` to notify again; saving it with the same one shows nothing more.
- It's skipped when the file was last modified more than 24 hours before Legato sees it.
- A `notify` that breaks the rules (no `id` or `body`, a `body` over 200 characters, a `title` over 60, or a key other than those three) stops the whole file loading: the page shows a warning card that says what's wrong, and its status file has `ok: false`. `set_page` and `legato set` refuse it with `invalid_page` and keep the old page.

A notification about a card also carries up to three of that card's buttons, so you can act on it from the notification. Only buttons that run without asking qualify: `"kind": "open"` buttons, and `http` buttons with a [`success`](https://legatobar.com/docs/buttons.md#buttons) check and no [`confirm`](https://legatobar.com/docs/button-tasks.md#buttons-that-ask-first). A button without a `success` check asks first in Shortcuts, and a notification can't ask, so it stays in the panel. Give a button a `success` check if you want it on the notification. See [Notifications](https://legatobar.com/docs/notifications.md).

## History

A source can keep rows from its answers on this Mac, for other pages to read later: deliveries a service forgets once they've arrived, readings it only reports as they are now. (To draw one number over time on a sparkline, use [Sparkline readings](https://legatobar.com/docs/mapping-sparklines.md#sparkline-readings) instead.) Add `collect` to the source, saying which items to keep, which of their fields, under what key and for how long:

```json
"collect": { "dataset": "parcel-deliveries", "each": ["active.deliveries", "recent.deliveries"],
             "key": "{carrier_code}:{tracking_number}",
             "fields": ["carrier_code", "tracking_number", "description", "events[].date", "events[].event"],
             "date": { "date": { "first": "date", "of": "events", "where": { "path": "event", "contains": "Delivered" } } },
             "keep": { "for": "400d" }, "readers": ["delivery-times"] }
```

A page listed in `readers` reads all matching rows with a source of its own, `{ "dataset": "parcel-deliveries" }`, filtered to its period. The rows stay on this Mac and don't sync; **Settings → History** shows what each page keeps, and exports or deletes it. Agents and scripts can add rows too, with `legato rows add`, when the owner declares `"accepts_rows": true`. Changes to retained fields, text removal or date rules update previously kept rows while collection pauses; Settings offers Re-key when the key template changes.

For a reading over time of every item of a fleet, such as each monitor's state every 5 minutes, add `"sample": { "every": "5m" }`: History then keeps one row per item per interval, for a year unless `keep` says otherwise. See [Samples](https://legatobar.com/docs/history-collect.md#samples).

A dataset source takes `key` to read one item's rows: `{ "dataset": "kuma-samples", "key": "{param.id}" }` on a [page for every item](https://legatobar.com/docs/detail-pages.md#one-page-for-every-item). The key is compared as text on both sides: kept keys are always text (collect refuses an item whose key is a number), and `key` is the text the link filled in, so `"7"` reads the item kept as `7` and `"07"` doesn't. A key a link didn't fill reads nothing, and the cards say "Open this page from an item's link".

A service that answers for a range of dates, such as Tessie's charges or GitHub's pull requests, doesn't need this: ask it for the period showing (see [Dates in requests](https://legatobar.com/docs/source-requests.md#dates-in-requests)).

See [History](https://legatobar.com/docs/history.md) for every field, dates, retention, readers and a complete Parcel example.



---

# Polling and failures

<a id="polling-and-failures"></a>

- Polling pauses while the Mac sleeps or is locked. On wake, unlock or panel open, sources refresh if due.
- Failures back off with repeated attempts, capped at 30 minutes or the configured interval if that is longer. They never shorten that interval. A success returns to the normal schedule.
- An answer can count as a failure too, when the service reports an error inside it: see [`fail`](https://legatobar.com/docs/source-polling.md#when-the-answer-reports-an-error).
- A data request gives up after 10 seconds without data, or 20 seconds in all, and has a 1 MB response limit, enforced while the answer downloads: Legato stops reading at 1 MB. Redirects must keep the same scheme, host and effective port.
- Before the first answer, a card shows what it is waiting for or an error. Later failures keep the last good value and add an error line. The footer shows the newest successful update on the page, so also check individual card errors.
- To read a page's sources again without waiting, click the arrow left of the pin at the top of the panel (⌘R). A server's cooldown still holds.
- macOS may ask for local-network access the first time Legato reaches a local service.

### When a service stops answering

A failed fetch keeps each card's last answer, with the error under it, so one dropped request doesn't blank a page. A service that has stopped answering for good would therefore stay green. Give the status card that stands for the service `failed`, and after a few failures in a row it says so:

```json
{ "id": "host", "type": "status", "label": "pve-lab", "state": "ok",
  "source": { "ref": "pve", "map": { "detail": "data.pveversion" },
              "failed": { "state": "critical", "detail": "Proxmox isn't answering", "after": 3 } } }
```

- The card takes that state and detail and notifies, as any status change does. Without `detail` it says "Not answering since 2:14 PM" (or "Not answering" when the source never answered).
- The next answer puts the card back to what the answer says.
- `after` counts failed fetches, which back off (see above): with `every` of `1m`, the third comes about 3 minutes after the first. Polling pauses while the Mac sleeps, so this tells you about the service only while the Mac is awake; for a service that must be watched around the clock, use a monitor such as Uptime Kuma as well.
- It applies before `when`, so a card that shows on a condition still shows when its source fails.
- A `fleet` takes `failed` too. Its items can't say how they stand while the source is silent, so the fleet shows one dot in their place, named by the card's label ("Server"), with that state and detail: it lights the page and notifies once, not once per item.
- A rate limit or a refused secret counts as a failure too: the card can't say what the service is doing.
- So does an answer the source's [`fail`](https://legatobar.com/docs/source-polling.md#when-the-answer-reports-an-error) turns down. Without `detail`, the card then says "Reporting an error since 2:14 PM", since the service is answering.

### When the answer reports an error

Some services answer HTTP 200 even when the request went wrong, and say so in the body: GraphQL APIs send an `errors` list, others `success: false`. Legato would take that as an answer, and the cards would show dashes. Give the source `fail`, and such an answer counts as a failed fetch:

```json
"sources": { "gh": { "url": "https://api.github.com/graphql", "method": "POST", "secret": "github", "body": { "query": "{ viewer { login } }" },
                     "fail": { "when": { "path": "errors", "exists": true }, "message": "errors[0].message" } } }
```

- `when` is a [condition](https://legatobar.com/docs/mapping-conditions.md#conditions), checked on the answer after [`derive`](https://legatobar.com/docs/mapping.md#derived-values), so it can test a derived value. `all` and `any` combine tests.
- **Test that the error is there** with [`exists`](https://legatobar.com/docs/mapping-conditions.md#conditions). Any other test whose path is missing or null doesn't hold here, whatever it compares, so an answer without `errors` passes; `equals: null` never fires.
- `message` is a [rule](https://legatobar.com/docs/mapping.md#mapping) for the service's reason. The note under the cards is "api.github.com reported an error: Bad credentials", on one line and cut at 200 characters, or "api.github.com reported an error" when there's no `message` or it gives nothing.
- It's then exactly a failed request: each card keeps its last answer with the note, polling [backs off](https://legatobar.com/docs/source-polling.md#polling-and-failures), a status card's `failed` counts it, and [History](https://legatobar.com/docs/source-reference.md#history) and [sparkline readings](https://legatobar.com/docs/mapping-sparklines.md#sparkline-readings) keep nothing from it. A rate limit the response's headers announce still holds.
- `fail` goes in `sources.<name>`, since it decides for every card on the source; a card's `failed` says what one status card shows after several failures. Only HTTP sources take it: calendars, reminders and History are read on this Mac.
- Adding `fail` to a source that [collects](https://legatobar.com/docs/source-reference.md#history) keeps its history as it is: the same rows and the same history in Settings → History.
- **Preview Source** shows an answer that `fail` turns down, with the reason above the cards.
- **A GraphQL answer can carry data and errors together**, such as one repository it couldn't read in a list of twenty. A rule on `errors` alone then holds the whole page on its last answer. Fail only when something every good answer has is missing: `{ "all": [ { "path": "errors", "exists": true }, { "path": "data.viewer.repositories", "exists": false } ] }`.

| Service | `fail` |
| --- | --- |
| GitHub GraphQL, Linear | `{ "when": { "path": "errors", "exists": true }, "message": "errors[0].message" }` |
| Cloudflare | `{ "when": { "path": "success", "equals": false }, "message": "errors[0].message" }` |
| Parcel | `{ "when": { "path": "success", "equals": false }, "message": "error_message" }` |
| Tautulli | `{ "when": { "path": "response.result", "not": "success" }, "message": "response.message" }` |
| SABnzbd | `{ "when": { "path": "status", "equals": false }, "message": "error" }` |

With [named requests](https://legatobar.com/docs/source-requests.md#requests-and-formats), the path starts with the request's name: `gql.errors[0].message`, or `{ "any": [ … ] }` over several.

### Rate limits and unchanged responses

- **Server-requested waits.** Legato honors `Retry-After` as seconds or an HTTP date on HTTP 429, on 503 when it carries `Retry-After`, and on 403 responses carrying rate-limit signals. A 503 without `Retry-After` is an ordinary failure and backs off as usual. Ordinary permission-denied 403 responses are treated as errors, not quota signals. A recognized rate-limit refusal without a usable deadline waits at least 60 seconds.
- **Exhausted quotas.** When `X-RateLimit-Remaining` or `RateLimit-Remaining` reaches 0, Legato waits for the matching `X-RateLimit-Reset` or `RateLimit-Reset`. Services send that in different forms, and Legato reads any of them: a delay in seconds, a Unix timestamp (any number from 1,000,000,000 up), an HTTP date or an ISO 8601 date. A successful response can therefore postpone the next poll too. Where several hints apply, Legato keeps the latest deadline, but no hint holds a source back for more than 24 hours.
- **Shared waits.** Sources using the same origin and configured credentials share the cooldown. Polling, **Fetch Once** and buttons respect it; an early request shows when it can try again. Rate-limited button and checklist-row commands are never replayed automatically. After the wait, click the button or tick the row again if you still want the action.
- **Conditional GETs.** For eligible GET requests, Legato retains the response and its ETag or Last-Modified validator in memory. A later request sends `If-None-Match` or `If-Modified-Since`; HTTP 304 reuses that response and reevaluates the current mappings and derived values. It does not fetch a full body again.
- **Cache boundaries.** POST reads and button requests are not cached. Cached responses are separated by URL and request headers, including authentication; changing credentials does not reuse another credential's data. `no-store` and `Vary: *` prevent storage. This is not an offline cache: reuse requires a server's 304 response, and the cache is lost when the app closes.



---

# Signing in and requests

## Signing in

`auth` says how the secret reaches the service. It applies to every request the source makes and to its buttons, except a request that reads [a public address](#a-public-address-beside-the-service).

| `auth` | Sends |
| --- | --- |
| omitted, or `{ "type": "bearer" }` | `Authorization: Bearer <secret>`. Most API keys and tokens: Tessie, Home Assistant, GitHub. |
| `{ "type": "header", "name": "X-Api-Key" }` | The secret in that header. |
| `{ "type": "header", "name": "Authorization", "value": "MediaBrowser Token=\"{secret}\"" }` | That header, with the secret where `{secret}` is. For services that want words around the key, such as Jellyfin and Emby. |
| `{ "type": "query", "name": "apikey" }` | The secret as `?apikey=…` on each request. |
| `{ "type": "basic" }` | HTTP Basic. A secret of `user:password` is sent as is; one without a `:` is sent as the password with no user name, which is how Uptime Kuma takes API keys. |
| `{ "type": "login", … }` | Signs in with a request first, keeps the token it gets back, and sends that instead. See below. |
| `{ "type": "oauth_client", "token_url": "/oauth/token" }` | Signs in as an OAuth client, trading its ID and secret for a short-lived access token, and sends the token as `Authorization: Bearer`. See [OAuth clients](#oauth-clients). |
| `{ "type": "none" }` | Nothing. |

A header's `value` holds `{secret}` exactly once and nothing else in braces, in at most 200 characters. The secret in Settings → Secrets is just the key; the page holds only the words around it:

```json
"auth": { "type": "header", "name": "Authorization", "value": "MediaBrowser Token=\"{secret}\"" }
```

It goes wherever the source's sign-in does: every request, its buttons, following a task, and images on its rows. Preview Source shows it as `Sends Authorization: MediaBrowser Token="…"`. A secret with a line break is never sent. If a service echoes the secret back in an answer or an error, Legato replaces it with "…" before a card, History or Preview Source sees it (for secrets of 6 characters or more, so a short one can't blank ordinary words).

A login describes the sign-in request, where the token is in its answer, and how to send the token. This `auth` field is a fragment to place inside a named source:

```json
"auth": {
  "type": "login",
  "request": { "method": "POST", "path": "/api/auth", "body": { "password": "{secret}" } },
  "token": "session.sid",
  "send": { "header": "X-FTL-SID" },
  "logout": { "method": "DELETE", "path": "/api/auth" }
}
```

- `{secret}` in the request's body or headers is replaced with the secret.
- `send` is `{ "header": name }`, `{ "query": name }` or `{ "bearer": true }` (the default).
- Legato keeps the token until a request is refused with HTTP 401, then signs in once more. A fetch and a button press at the same moment share one sign-in.
- Login requires a nonempty token at the declared path; a missing token is an error. For a passwordless service, use `{ "type": "none" }` instead of a login.
- `logout` (optional) signs the session out: when Legato quits, and when the credential for the same named secret changes and an old session is replaced. Different secret names keep separate sessions, even on the same service. It's a path or `{ method, path, headers, body }`, `DELETE` by default, and carries the token the way `send` says. Give it for services that limit how many sessions are open at once, such as Pi-hole, or every launch leaves one behind until it expires. Updating `logout` applies to an existing session on the next fetch; if pages sharing the same sign-in and secret name disagree, the most recently used recipe supplies the logout policy. Quit cleanup includes sign-ins still finishing, but a crash or an unresponsive service can leave a session until the service expires it.

### OAuth clients

Some services, Tailscale among them, let you make an OAuth client for an app like Legato. A client has an ID and a secret that last until you revoke them, so you don't have to swap in a new key every few months. Legato trades the two for an access token (OAuth's client credentials grant) and sends that token with every request:

```json
"secret": "tailscale-client",
"auth": { "type": "oauth_client", "token_url": "/api/v2/oauth/token" }
```

- Save the client in Settings → Secrets as `client-id:client-secret`, the ID and the secret joined by a colon. Legato splits it at the first colon, so the secret itself may hold colons but the ID can't. From 1Password, the ID and the secret can come from [two fields](https://legatobar.com/docs/1password.md#a-secret-in-two-fields).
- `token_url` is the service's token endpoint: a path on the source's address, after any `base`, or a full URL on that same address. A token endpoint on another host isn't supported.
- `scope` (optional) is the scopes to ask for, separated by spaces, such as `"devices:core:read"`. Leave it out to get what the client was given.
- `client_auth` (optional) is `"body"`, the default, which sends the ID and secret in the form, or `"basic"`, which sends them as HTTP Basic for services that want it that way.
- The token stays in memory only: never on disk, in History or in Preview Source. Legato gets a new one shortly before it runs out (going by the `expires_in` the service gives) and when a request is refused with HTTP 401. It drops the token when the secret changes and when Legato quits. A fetch and a button press at the same moment share one token.
- If the service turns the client down, the card says so. It shows OAuth's error code when the service sends one, as in "refused the OAuth client (invalid_client)", and the HTTP status when it doesn't, as in "api.tailscale.com refused the OAuth client (HTTP 401)". A 403 on a request means the client's scopes don't cover it.

### Connections

Some services let Legato sign in through your browser, so there's no token to copy. Todoist is the first. In Settings → Secrets, a secret for one of these services offers **Connect**. Legato opens the service's sign-in page in your browser, you sign in and allow access, and Legato saves the connection under the secret's name. A template for the service offers Connect in its Sign in step too.

```json
"url": "https://api.todoist.com/api/v1",
"secret": "todoist"
```

- A page names a connection as it names any secret, with the default `bearer` auth, so the same page works with a connection or a pasted token.
- Legato keeps the connection in this Mac's Keychain and gets a fresh access token from the service shortly before the old one runs out.
- The token goes only to the service's API host (`api.todoist.com`), over HTTPS, as a Bearer token. A source that would send it another way or to another address fails and says why. A host list can't use a connection.
- Each Mac connects on its own. A connection can't come from 1Password and has no expiry date.
- When the service no longer accepts the connection, Settings → Secrets shows it as needing attention, and **Connect Again** signs in once more.
- **Disconnect**, in the secret's menu, signs Legato out of the service and deletes the connection from this Mac. You can also remove Legato in the service's own settings.

## Requests and formats

A source makes one request to its `url`, or several named ones. These fields are a source fragment:

```json
"url": "http://pi.hole",
"requests": {
  "summary": "/api/stats/summary",
  "blocking": "/api/dns/blocking",
  "top_blocked": "/api/stats/top_domains?blocked=true&count=10"
}
```

The answer is then `{ "summary": …, "blocking": …, "top_blocked": … }`, one key per request, so paths in `map` start with the request's name: `summary.queries.total`. Each request is a path on the source's origin, or an object with `path`, `method`, `body`, `headers` and `format`. It cannot change the source's scheme, host or port, except to read [a public address](#a-public-address-beside-the-service). Request-specific headers override common source headers.

`format` says how to read an answer:

| `format` | Reads |
| --- | --- |
| `json` (the default) | JSON. An answer that's JSON inside a string, such as a rendered template, is read as the JSON inside. |
| `text` | The text, as one string. |
| `feed` | An RSS, Atom or JSON feed, as `{ "title", "url", "count", "items" }`; see [A feed](https://legatobar.com/docs/source-examples.md#a-feed-the-latest-posts-each-linking-to-its-page). |
| `prometheus` | Prometheus metrics text, as a list of `{ "name", "labels", "value" }`. |
| `docker-logs` | Docker log frames or plain TTY text, as `{ "lines": [{ "stream": "stdout", "time": "2026-11-09T12:00:00Z", "text": "Ready" }], "count": 1 }`. |

For Docker logs, request `/containers/{id}/logs?stdout=1&stderr=1&tail=20&timestamps=1` with `"format": "docker-logs"`. Lines stay in response order, newest last. Each line names `stdout` or `stderr`. Plain TTY text uses `stdout`. `time` is present only when the line starts with an RFC 3339 timestamp. ANSI colour codes and trailing newlines are removed. Invalid UTF-8 is replaced. The answer keeps the last 200 lines and cuts each text to 500 characters. An invalid or truncated frame makes the response read as plain text.

### Requests from a list

A watchlist is the person's own, so its symbols go in a [list](https://legatobar.com/docs/lists.md#sending-a-list) in Settings → Lists, where a page file can't carry them, and a named request sends them. `each_entry` sends the request once for each entry of the list, with `{entry}` in its path filled in:

```json
"url": "https://finnhub.io",
"secret": "finnhub",
"auth": { "type": "header", "name": "X-Finnhub-Token" },
"requests": {
  "quotes": { "path": "/api/v1/quote?symbol={entry}", "each_entry": { "list": "stock-watchlist", "max": 30 } }
}
```

The answer at `quotes` has one row per entry, in the list's order:

```json
"quotes": [
  { "entry": "NRWD", "answer": { "c": 184.62, "dp": 2.32 } },
  { "entry": "ZZZZ", "error": "finnhub.io answered HTTP 404" }
]
```

A card maps the rows with `each`, reading `entry` and `answer`: `{ "each": "quotes", "where": { "path": "answer", "exists": true }, "fields": { "text": "entry", "detail": { "template": "{answer.c}" } } }`.

- `list` names the list. `max` is how many entries are sent: the first ones in the list that can be sent, 1 to 50, 20 if you leave it out. Entries after that get a row saying "Not sent: this page sends the first 30 entries".
- Each entry is checked first, as a [page param](https://legatobar.com/docs/detail-pages.md) is: 1 to 64 of `A–Z`, `a–z`, `0–9`, `.`, `_`, `~` and `-`, and never `.` or `..`. With `"type": "text"`, an entry can be a short name of up to 40 letters, digits, spaces and `. , ' - ( ) &` instead. `pattern` is a regular expression the whole entry must also match. An entry that doesn't pass is never sent, and its row says so.
- The entry is encoded and goes only in the path or query, never the host, a header or a body. A request with `each_entry` is a GET.
- An entry listed twice is sent once.
- Each entry's answer can be up to 256 KB. A list of more than 200 entries fails the request instead of making a row for each.
- Each `each_entry` request has at most 4 entries out at a time, and requests to one service with one secret leave at least 0.1 seconds apart, so 30 entries take about 3 seconds.
- If one entry fails, only its row has an `error`. The whole source fails, and cards keep their last answer with a note, when the service refuses the secret (HTTP 401), asks Legato to wait (HTTP 429, or quota headers), can't be reached, has a certificate to review, or fails every entry.
- While the list is missing or empty, nothing is sent, the answer is `[]`, and cards using the source say "Add the list stock-watchlist in Settings → Lists".
- A source makes at most 64 requests a fetch, counting each `each_entry` as its `max`: room for quotes and company profiles for 30 symbols, plus one more.
- When the list changes, the source is read again right away. An answer that was on its way for the old list is dropped, and nothing from it is kept in History.

`all_entries` sends the request once, with every entry in place of `{entries}`, separated by commas:

```json
"prices": { "path": "/api/v3/simple/price?ids={entries}&vs_currencies=usd", "all_entries": { "list": "coins", "max": 50 } }
```

- Entries are checked and encoded as for `each_entry`. An entry with a comma in it can't be sent.
- `max` is the most entries the list can hold: 1 to 100, 50 if you leave it out. With more, or with an entry that can't be sent, nothing is sent, and cards say which list to fix and which entry: "Entry 3 of the list coins can't be sent; check it in Settings → Lists".
- While the list is missing or empty, nothing is sent and the answer is `null`.
- The answer is the service's, as with any request.

Settings → Lists names the services a page sends each list to, and Details shows "Sends the list stock-watchlist" under the source. A template asks for the list with a `list-name` input that fills `each_entry.list` or `all_entries.list`, and a `lists` entry whose `why` says where its entries go.

To keep history for each entry, `derive` the rows that answered and [collect](https://legatobar.com/docs/history-collect.md#samples) them with `"key": "{entry}"`. A detail page then reads one entry's samples with `{ "dataset": "stock-prices", "key": "{param.symbol}" }`.

### A request for each row

Some services list things by id and keep the names elsewhere. Seerr's waiting requests carry a TMDB id and whether it's a movie or a show, and each title is its own request. `each_row` sends a named request once for each row of another request's answer, with the row's fields in braces filling its path:

```json
"url": "http://192.0.2.40:5055",
"secret": "seerr",
"auth": { "type": "header", "name": "X-Api-Key" },
"requests": {
  "pending": "/api/v1/request?filter=pending&take=20",
  "titles": { "path": "/api/v1/{media.mediaType}/{media.tmdbId}",
              "each_row": { "from": "pending.results", "key": "id", "max": 20,
                            "pick": ["title", "name", "releaseDate", "firstAirDate", "posterPath"], "keep": "6h" } }
}
```

The answer at `titles` has one row per row of `pending.results`, in the same order, each with the row's `key`:

```json
"titles": [
  { "key": 41, "answer": { "title": "Saltmarsh", "releaseDate": "2024-03-08", "posterPath": "/s4ltm4rsh.jpg" } },
  { "key": 42, "error": "192.0.2.40 answered HTTP 404" }
]
```

A card joins the two with a [lookup](https://legatobar.com/docs/mapping.md#mapping): `"lookup": { "from": "titles", "by": "key", "on": "id", "as": "title" }`, then reads `title.answer.title`.

- `from` names another of the source's requests, then where its rows are in that answer (`pending.results`, or just `pending` when the answer is the list). An object there is one row: Gitea's repository answers at `/repos/{owner}/{repo}`, and `"from": "repo"` sends one request about its default branch, so a branch Legato can't send (`release/2026`) fails that row, not the source. It's sent after the source's other requests and reads that answer as it came, before `derive`. That request has to be an ordinary one answering JSON, a request with [`with`](#a-value-from-another-answer), or a request for each row of an ordinary one (below). It can't read a list's entries or a [public address](#a-public-address-beside-the-service), so a fetch is never more than three rounds.
- **Rows from a `with` request.** Gitea's repository search narrows to the person's own repositories only with their numeric id, which `/api/v1/user` answers. `"repos": { "path": "/api/v1/repos/search?uid={uid}&limit=25", "with": { "uid": "me.id" } }` goes in the second round, and a request for each row with `"from": "repos.data"` goes in the third. Its rows are read as from an ordinary request, with no `parent_key`, and nothing can read its answers in turn.
- **Rows inside rows.** A request for each row can read another one's answers, one level deep. UniFi's console lists its sites, each site's devices at `/sites/{id}/devices`, and each device's statistics at `/sites/{site}/devices/{id}/statistics/latest`. With `"from": "devices.data"`, where `devices` is itself sent for each site, the rows are the devices inside every site's answer, in order. Each gets `parent_key`, the key of the site it came from, for its path: `"path": "/sites/{parent_key}/devices/{id}/statistics/latest"`. A site whose request failed gives no devices. When the path after the name leads to one object rather than a list, that object is one row: Gitea's pull request answers at `/pulls/{number}`, so `"from": "pulls"` reads each one whole, and `"path": "/repos/{base.repo.owner.login}/{base.repo.name}/commits/{head.sha}/status"` asks for its head commit's checks. Past 200 rows in all, the first 200 are read, and as always only the first `max` are sent. A third request reading the second's rows isn't allowed.
- `key` is the field that names each row, a string or a number. It comes back with each answer for the lookup. A row with no key, or with the same key as an earlier row, isn't sent, and its row has `"key": null` and an `error`.
- Each `{field}` is a path in the row. Its value has to be a string or a whole number that would pass as a [page param](https://legatobar.com/docs/detail-pages.md): 1 to 64 of `A–Z`, `a–z`, `0–9`, `.`, `_`, `~` and `-`, never `.` or `..`. It's encoded as one segment and goes only in the path or query, on the source's own address: never a host, a header or a body. A request for each row is a GET. A row whose value can't be sent gets an error row.
- `max` is how many rows are sent, the first that can be: 1 to 50, 20 if you leave it out. Rows after that say "Not sent: this page sends the first 20 rows".
- `pick` names the top-level fields to keep from each answer. Seerr's movie answer runs to 40 KB of cast and trailers, and a title needs a few fields of it.
- `keep` reuses an answer for that long before asking again, from `1m` to `24h`. Use it for answers that don't change, like a film's title, so a button's follow-up reads don't ask again for every row. Kept answers stay in memory, for that address and secret only. A failed answer is never kept.
- Calls go as a list's do: 4 at a time, 0.1 seconds apart to one service, each answer up to 256 KB, and more than 200 rows fails the request. A row that fails, even every one of them, fails only its own row, since the rows' own request already reached the service. A refused secret, a request to wait or an unreachable host fails the source.
- It counts as its `max` toward a source's 64 requests a fetch. It can't be used in a source with [hosts](#several-hosts-from-a-list).

### A request with nothing there yet

Some services answer 404 for something that will exist later. changedetection.io's latest difference is 404 until a watch has changed once, and a source fails on a 404, so a watch that never changes would keep its page in error. Give that request `missing`, the statuses that mean nothing is there yet:

```json
"requests": {
  "watch": "/api/v1/watch/{param.uuid}",
  "diff": { "path": "/api/v1/watch/{param.uuid}/difference/previous/latest", "format": "text", "missing": [404] }
}
```

- An answer with one of those statuses leaves the request's name out of the source's answer, so test it with `exists: false` or give the card an `empty`. Any other failure fails the source as before.
- `missing` is `[404]`, `[410]` or both. It goes on one request to the service: not with `each_row`, `each_entry`, `all_entries`, `follow` or `"auth": { "type": "none" }`.

A request for detail the cards can do without takes `"optional": true` instead. changedetection.io's report of the week's changes adds a line to each watch, and a big install can take longer to answer it than Legato waits. When an optional request fails, for an error status, no answer in time or an answer too large, its name is left out and the other requests still fill the cards. An optional request that takes a value from another answer (`with`) and doesn't find it is left out too. A refused secret, a 403 or a request to wait still fails the source, since those are about the key or the whole service. It goes on the same kind of request as `missing`.

### A value from another answer

Some requests need an id that another request answers. Cloudflare lists tunnels under an account, and the account's id comes back with the zones. `with` names the value and where it is in the other answer, and `{name}` in the path takes it:

```json
"url": "https://api.cloudflare.com",
"secret": "cloudflare",
"requests": {
  "zones": "/client/v4/zones",
  "tunnels": { "path": "/client/v4/accounts/{account}/cfd_tunnel?is_deleted=false",
               "with": { "account": "zones.result[0].account.id" } }
}
```

- Each value is another request's name, then where the value is in its answer: `zones.result[0].account.id`, or `nodes[0].node` when the answer is a list. The request goes after the source's other requests and reads that answer as it came, before `derive`.
- That request has to be an ordinary one answering JSON. It can follow pages, but it can't have `with`, `each_row`, `each_entry`, `all_entries` or `"auth": { "type": "none" }` itself, so a request with `with` always goes in the round after the requests it reads.
- A value can also be a list of up to 3 places, tried in order: the first that has a value is sent. Pi-hole's Queries page asks about the query a link picked, else the newest: `"with": { "d": ["pick.queries[0].domain", "newest.queries[0].domain"] }`.
- `with` names 1 to 4 values. A name is a lowercase word, such as `account` or `node_id`, and can't be one Legato fills itself, like `date` or `secret`. Every name goes in the path or a body string, and every `{word}` in the path has to be one of them.
- The value has to be a string or a whole number that would pass as a [page param](https://legatobar.com/docs/detail-pages.md): 1 to 64 of `A–Z`, `a–z`, `0–9`, `.`, `_`, `~` and `-`, never `.` or `..`. In the path it's encoded as one segment. In a JSON body string it goes in as it is, for a GraphQL query's variables: `"body": { "query": "…", "variables": { "accountTag": "{account}" } }`. Other braces in the body go out as written. A value never goes in a header or the host.
- When the value is missing or can't be sent, this request isn't sent, and the source fails with a note that says where the value was looked for: "tunnels needs zones.result[0].account.id, which zones didn't answer". Cards keep their last answer, as for any failure.
- A request with `with` can also follow pages. It can't send a list's entries or be sent for each row, and it can't be used in a source with [hosts](#several-hosts-from-a-list). It counts as one request toward the 64 a fetch, or as `follow`'s `max`.

### A public address beside the service

A source with a secret keeps its requests on its own address. A request can read a public address as well, with `"auth": { "type": "none" }` and a full `https://` URL as its path. The Cloudflare source above can read GitHub's latest connector release, so a card can compare it with the version the tunnel runs:

```json
"release": { "path": "https://api.github.com/repos/cloudflare/cloudflared/releases/latest", "auth": { "type": "none" }, "keep": "6h" }
```

A public API may limit how often a Mac without a key can ask, and a release changes far less often than a tunnel's state. `keep` makes Legato reuse the answer it last read for that long, from `1m` to `24h`, before asking that address again. The kept answer stays in memory, for that address only, and a request with a secret never gets it.

When the public address fails, the rest of the source still answers. That covers an error status, an unreachable host, an answer too large or one Legato can't read, and a request to wait. The request then gives its last good answer from the past day, or nothing, so `release` is missing and an `exists` test on it is false. Source Preview shows the answer it got, without the public host's error.

- It's sent with none of the source's sign-in: no secret, no token from a login or an OAuth client, no secret in the query, and none of the source's `headers` or `base`.
- Its own `headers` can hold fixed values, such as an `Accept` the service asks for. They can't be `Authorization`, `Proxy-Authorization`, `Cookie` or `Host`, and they can't have braces. `{secret}` can't go anywhere in it.
- It's a GET of one answer, over https, with no login in the URL. It can't have `method`, `body`, `with`, `each_row`, `each_entry`, `all_entries` or `follow`, and other requests can't take values from its answer.
- A redirect stays on that address. A refusal there (HTTP 401 or 403) is never taken as a refused secret. When that host asks Legato to wait, its public requests wait until then, in every source, and the service's own requests go on as before.
- `keep` goes only on a request with `"auth": { "type": "none" }`. A request for each row takes its own `keep` in `each_row`.
- Details and Source Preview list its host beside the service's.

### A list across pages

Many APIs answer a long list a page at a time and say whether there's more. Stripe answers 100 payments at most, with `"has_more": true` when there are others, and the next page starts after the last one's `id`. `follow` asks again until the list ends, putting the next page's cursor in a query parameter, and joins the pages:

```json
"url": "https://api.stripe.com",
"secret": "stripe",
"requests": {
  "moves": { "path": "/v1/balance_transactions?created[gte]={period.start_unix}&created[lt]={period.end_unix}&limit=100",
             "follow": { "items": "data", "while": "has_more", "param": "starting_after", "from_last": "id", "max": 10 } }
}
```

The answer at `moves` is the first page with every page's items at `data`, in order, and `has_more` from the last page read. So a period with more than 1,000 movements still says `true`, and a card can say it shows only part of them.

- `items` is where each page's list is, and `while` the field that's `true` while there's another page. Both are fields of the answer, not inside a list.
- Some services say there's more only by sending a cursor, and leave it out on the last page. UniFi's Site Manager answers `nextToken` until the list ends. Leave `while` out and give `from`, and the list goes on while that cursor is there: a page with no cursor, `null` or empty text is the last. Such a page may come back short, or even empty, with a cursor, and the next one is still read. `"follow": { "items": "data", "param": "nextToken", "from": "nextToken", "max": 4 }`
- The cursor comes from `from_last`, a field of the page's last item (Stripe's `id`), or from `from`, a field of the page itself. Stripe's search answers `next_page`, sent back as `page`: `"param": "page", "from": "next_page"`. With `from`, the joined answer takes that field from the last page too.
- `param` gets the cursor, encoded once; an earlier value of it in the path is replaced, and every other parameter stays as written. A cursor is never read for `{…}` tokens.
- `max` is how many pages are read at most, the first included: 1 to 20, 10 if you leave it out. It doesn't change how many items a page holds: that's the service's own parameter (`limit=100`).
- The pages go one after another, 0.1 seconds apart. If any page fails, has no list, has no `true` or `false` at `while`, says there's more with an empty list (with `while`), or gives no cursor or one already read, the whole request fails. A card never shows totals from part of the pages, and keeps its last good answer as it does for any failure.
- Other fields of the answer, such as a count or a page number, are the first page's. Legato doesn't drop repeats: when a service's pages repeat an item, as Stripe's search sometimes does, the joined list has it twice. Count from a list, not a search.
- At most 10,000 items and 8 MB joined, besides each page's 1 MB. It's a GET answering JSON, and can't be combined with `each_entry`, `all_entries` or `each_row`; a request for each row may read a followed answer's rows. It counts as its `max` toward a source's 64 requests a fetch.

### Several hosts from a list

Some services run the same API on many hosts: every vendor's status page answers at `/api/v2/summary.json`, and every Glances box at `/api/4/`. A source with `hosts` in place of `url` reads every host on a [list](https://legatobar.com/docs/lists.md#lists) in Settings → Lists, with the same requests, and gives one row for each:

```json
"status": {
  "hosts": { "list": "status-pages", "max": 30 },
  "every": "2m",
  "requests": { "summary": "/api/v2/summary.json" },
  "derive": [ { "name": "name", "value": "summary.page.name" } ],
  "fail": { "when": { "path": "summary.page.id", "exists": false } }
}
```

Each entry on the list is an address: a host name, read over https (`www.githubstatus.com`), or an address with its scheme and port (`https://status.example.com:8443`, `http://192.168.1.20:61208`). The answer at `hosts` has a row for every entry, in the list's order:

```json
"hosts": [
  { "entry": "www.githubstatus.com", "origin": "https://www.githubstatus.com", "key": "h3f9a2c1e07b4d55",
    "host": "www.githubstatus.com", "state": "answered", "answer": { "name": "GitHub" } },
  { "entry": "status.example.net", "origin": "https://status.example.net", "key": "h81d0e7b2c4a9f6e",
    "host": "status.example.net", "state": "failed", "fails": 2, "last_success": "2026-11-12T15:04:00Z",
    "answer": { "name": "Example" }, "error": "status.example.net didn't answer" }
]
```

A card maps the rows with `each`, reading each host's own answer under `answer`. A fleet from the rows:

```json
{ "each": "hosts", "fields": {
  "name": { "if": { "path": "answer.name", "exists": true }, "then": { "template": "{answer.name|clip:24}" }, "else": { "template": "{host|clip:24}" } },
  "state": { "if": { "path": "state", "equals": "answered" }, "then": "answer.rating", "else": { "template": "unknown" } },
  "url": "origin" } }
```

- **Each host is a source of its own.** It gets the requests, `derive` and `fail` as written, against that host. With `derive`, its row's `answer` holds only the values `derive` made, so derive what the cards need. Without `derive`, the row holds the whole answer, which for a status page's incident history can be 500 KB a host. A host that fails, or whose answer `fail` turns down, has `state` `failed` and an `error`; the others answer as usual. A fetch fails as a whole only when Legato is signing out or the read is cancelled.
- **A host that stops answering keeps its last answer** (in memory: not after Legato restarts). Its row is `failed`, with the `error`, how many reads in a row it has failed (`fails`, which counts up to 10), when it last answered (`last_success`) and its last `answer`. The card's own rules decide what that means: `{ "path": "state", "equals": "answered" }` greys a dot at once, and `{ "path": "fails", "gte": 3 }` turns a server red after three missed reads, showing its last readings until then. An answered row has `fails` 0 and no `last_success`.
- **`state`** is `answered`, `failed`, `not_sent` (an entry that isn't an address a host list reads, or one past `max`) or `over_budget` (a read that has already kept as much as it can). `key` is the same for the same address however it's written, and changes when the address does.
- **Addresses.** `https` goes to a DNS name, an IPv4 address, a `.local` name or a single word, such as `atlas`. Plain `http` goes only to the last three, which macOS allows for local networks. An entry has no path, user or query, IPv6 addresses aren't read yet, and an address listed twice is read once. A certificate a server made for itself is trusted as for any source: at an IP address or a `.local` name, once you trust it. The check is of the address's shape: a name you add can still lead to a server on your own network.
- **Signing in.** A host-list source may name a `secret` and an `auth` of `basic`, `bearer`, `header` or `query` (not a login or an OAuth client). Each host gets the secret saved under that name for its own address: save it once for each host in Settings → Secrets, as `glances:password` for basic sign-in. With `"secret_optional": true`, a host with none saved goes without signing in. Settings → Secrets lists a required secret once for each host, and an optional one not at all. A host that wants a password says so on its own row (HTTP 401). A secret goes only to the host it was saved for: on any of its ports, and over plain `http` when the entry is written that way. A host list has no headers of its own: each host gets the `Accept` and `User-Agent: Legato` headers every source sends, its secret, and cache validators for an answer it already gave. Every request is a GET to a path on the host, and a redirect stays on the same host.
- **Limits:**
  - `max` is 1 to 30 hosts, read four at a time, with up to 6 requests each and 180 in all (`max` × requests). Requests from a list (`each_entry`, `all_entries`) can't go inside one.
  - Each host's answer can be up to 1 MB, and a read keeps up to 8 MB in all.
- **When every host fails,** the rows still come back, each `failed` with its kept answer, so cards show each host as it stands. The source itself counts as answered, so it keeps reading at its own interval rather than backing off.
- **List changes.** A list longer than 200 entries fails the source. When the list changes, the source is read again right away. While it's missing or empty, nothing is read, `hosts` is `[]`, and cards say to add the list.
- **What it can't do:**
  - `title_from` can't read a whole host list, which has no one name for the page.
  - A card reading a whole list can't have buttons: link each row to its host with `url`, or to a page for that host (below).
  - It can't `collect`.
  - `{period.…}` can't be used in it, and `{param.…}` only as `only` (below).
- Settings → Lists says the page reads each entry as an address, and Details names the list.

#### A page for one host on the list

A row can open a page about that host alone. Give the page a param with `list_key`, naming the list, and a source with `only`:

```json
"params": { "box": { "list_key": "glances-hosts", "example": "h0000000000000000" } },
"sources": { "glances": {
  "hosts": { "list": "glances-hosts", "only": "{param.box}" },
  "secret": "glances", "secret_optional": true, "auth": { "type": "basic" },
  "requests": { "system": "/api/4/system", "quicklook": "/api/4/quicklook" } } }
```

Link to it from a row with `"url": { "template": "legato://page/glances-box?box={key}" }`.

- **The source reads that one host,** as an ordinary source on its address, with the secret saved for it. It answers as that source would, with no rows. Its buttons go to that host, `title_from` can read it, and two or three such sources on one page read the same host.
- **A key names one address.** It's made from the address, so a link can never point the page at another host, and only a host the list holds is read. A key the list doesn't hold reads nothing, its buttons do nothing, and the cards say "This address isn't on the list glances-hosts". That includes an old link once the address is edited, which makes a new key.
- **No default yet:** the page is opened from a row.

### Several feeds from a list

A person's feeds are their own, so their addresses go in a [list](https://legatobar.com/docs/lists.md#lists), not in the page. A source with `feeds` in place of `url` reads every feed address on the list, as RSS, Atom or JSON Feed, with no sign-in:

```json
"feeds": {
  "feeds": { "list": "news-feeds", "max": 30 },
  "every": "30m"
}
```

The answer has a row for each entry under `feeds`, as a [host list](#several-hosts-from-a-list) has under `hosts`, and every feed's posts together under `items`:

```json
{ "feeds": [ { "entry": "https://example.com/feed.xml", "url": "https://example.com/feed.xml", "key": "h3f9a2c1e07b4d55", "host": "example.com",
               "state": "answered", "fails": 0, "answer": { "title": "Example Notes", "url": "https://example.com/", "count": 20, "items": [ … ] } } ],
  "items": [ { "title": "A post", "url": "https://example.com/a-post", "published": "2026-11-16T09:00:00Z", "author": "Riley",
               "feed": "Example Notes", "feed_key": "h3f9a2c1e07b4d55" } ],
  "count": 1 }
```

- **An entry is a whole feed address,** with its path and query: `https://example.com/blog/feed.xml?lang=en`, or `example.com/feed`, which is read over https. The scheme and host are lowercased and a default port dropped; the rest is kept as written, so `/feed` and `/feed/` are two feeds. Plain `http` goes only to an IP address, a `.local` name or a single word; a public `http://` entry gets a row saying to use its `https://` address. The same address listed twice is read once.
- **`items` is every feed's posts, newest first,** up to 200, with `feed` (the feed's title, or its host when it has none) and `feed_key` (its row's key). A post with no date goes after the dated ones, and one dated in the future sorts as now. A row's `answer` keeps the feed's newest 50 posts without their summaries; a failed feed keeps its last ones, which stay in `items`.
- **A feed that fails is its own row's error,** as a host is. A feed that asks for a password says so, and one that redirects to another address fails and says so: put the address it ends up at in the list.
- **A page for one feed** takes a `list_key` param and `"feeds": { "list": "news-feeds", "only": "{param.feed}" }`, linked from a row with `?feed={key}`. It answers as a [feed](https://legatobar.com/docs/source-examples.md#a-feed-the-latest-posts-each-linking-to-its-page) does, summaries and all but with its posts newest first, so `title_from` can name the page after the feed.
- **What it can't do:** a feed list has no requests, secret, headers or `derive` of its own, its cards have no buttons, `title_from` can't read a whole list, and it can't `collect`. `max` is 1 to 30 feeds, read four at a time, each answer up to 1 MB.

### Dates in requests

A request can ask for a date range that moves with the calendar: this month's budget, the last 30 days. Put a `{date.…}` token in a request's `path`, in a single request's `url` (its path or query), in a `body` string or in a header, and Legato fills it in each time the request goes out, in the Mac's time zone:

```json
"url": "https://api.lunchmoney.dev",
"requests": {
  "month": "/v2/summary?start_date={date.month_start}&end_date={date.month_end}"
}
```

| Token | Gives (on Sunday 25 Oct 2026) |
| --- | --- |
| `{date.today}`, `{date.yesterday}`, `{date.tomorrow}` | `2026-10-25`, `2026-10-24`, `2026-10-26` |
| `{date.week_start}`, `{date.week_end}` | The week's first and last days, as the Mac's calendar starts weeks: `2026-10-25`, `2026-10-31` |
| `{date.month_start}`, `{date.month_end}` | `2026-10-01`, `2026-10-31` |
| `{date.last_month_start}`, `{date.last_month_end}` | `2026-09-01`, `2026-09-30` |
| `{date.year_start}`, `{date.year_end}` | `2026-01-01`, `2026-12-31` |
| `{date.days_ago_7}`, `{date.days_ago_30}`, `{date.days_ago_90}` | `2026-10-18`, `2026-09-25`, `2026-07-27` |
| `{date.days_ahead_7}`, `{date.days_ahead_30}` | `2026-11-01`, `2026-11-24` |
| `{date.days_ahead_N}` | Any number from 0 to 3660 calendar days ahead. For a 30-day agenda including today, end at `{date.days_ahead_29}`. |
| `{date.now}` | The moment, with its offset: `2026-10-25T11:30:00-05:00` (encoded in a URL) |
| `{date.days_ago_N}` | Any number of days back, up to 3660: `{date.days_ago_29}` is `2026-09-26` |
| `{date.…_at}` | The moment a day starts, with its offset: `{date.month_start_at}` is `2026-10-01T00:00:00-05:00`. For an end day it's the moment after it, so `{date.month_end_at}` is `2026-11-01T00:00:00-05:00`, for APIs that take a range of moments with the end left out (Stripe's `lt`). `{date.now}` has none. |
| `{date.hours_ago_N_at}` | The moment N hours ago (1 to 720), with its offset: `{date.hours_ago_24_at}` for the last day of readings. |
| `{date.hour_back_N_at}` | The end of this hour, N hours back (0 to 9,000), on the hour: `{date.hour_back_0_at}` is the next hour's start, `{date.hour_back_24_at}` the same hour yesterday. `{date.hour_back_N_first}` and `{date.hour_back_N_last}` are the days a stretch that starts or ends there begins and ends on. A `last_hours` period uses these. |
| `{date.…_unix}` | Any `_at` moment, and `{date.now_unix}` and `{date.hours_ago_N_unix}`, in Unix seconds instead: `{date.month_start_unix}` is `1790830800`. For services that take those, such as Tessie's `from` and `to`. |

Day tokens include their last day. A service that counts both ends counts `{date.days_ago_30}` to `{date.today}` as 31 days; for 30 days today included, start at `{date.days_ago_29}`.

On a page with a [period](https://legatobar.com/docs/periods.md#periods), more tokens are the period chosen in its row: `{period.start}` and `{period.end}`, its first and last days; `{period.through}`, its last day so far, which is today while the period is still going and its last day once it's over; and `{period.start_at}`, `{period.end_at}` and `{period.through_at}`, the moments it starts and ends, with `{period.start_unix}`, `{period.end_unix}` and `{period.through_unix}` the same moments in Unix seconds. With `"compare": "previous"`, `{compare.start}`, `{compare.end}`, `{compare.start_at}` and `{compare.end_at}` are the same stretch of the period before. They can all go wherever `{date.…}` tokens can:

```json
"requests": {
  "spent": "/v2/summary?start_date={period.start}&end_date={period.end}"
}
```

Only these exact tokens are filled; other braces, such as a Home Assistant template's `{{ … }}` in a body, go out as written. A token Legato doesn't know fails the page when it loads. Dates can't go in the host, or in a login request.

With `prometheus`, `group_by` names a label to group by instead: one object per value of that label, holding its labels and each metric as a field. `split_by` lists labels that tell apart several samples of one metric; their values are added to the field's name. A response with no usable samples is an error. Uptime Kuma's `/metrics` with `"group_by": "monitor_id", "split_by": ["window"]` produces data like this example answer:

```json
[ { "monitor_id": "1", "monitor_name": "Gitea", "monitor_type": "http",
    "monitor_status": 1, "monitor_response_time": 25,
    "monitor_uptime_ratio_1d": 0.9965, "monitor_uptime_ratio_30d": 1 } ]
```



---

# Mapping

A service answers in its own shape, and a card has fields of its own: a stat's `value`, a list's `items`. A sourced card's `map` joins the two. Each key is a field of the card, and each value is a rule that says where it comes from in the answer.

The simplest rule is a path, such as `summary.queries.total`. Others fill in a template, build a list from an array, count or total it, choose between two rules on a condition, or do arithmetic. `derive` works a value out once on the source, and every card that uses the source can read it.

Paths, rules and the options a list takes are all below. Four subjects have a page each:

- [Names and tables](https://legatobar.com/docs/mapping-tables.md): Answers that use names as keys or parallel arrays, and tables that need flattening or grouping.
- [Expiry and slices of time](https://legatobar.com/docs/mapping-expiry.md): Days left on a certificate or a renewal, and a long series cut into a set number of slices.
- [Conditions](https://legatobar.com/docs/mapping-conditions.md): The tests a rule, a card or a button can make on the answer.
- [Sparkline readings](https://legatobar.com/docs/mapping-sparklines.md): A sparkline of a value the service only reports as it is now.

## Derived values

`derive` works out values from the answer and adds them to it, in order, so a later one can use an earlier one, and so can `map`. Each entry is a name and a [rule](https://legatobar.com/docs/mapping.md#mapping). This source fragment assumes its named requests produce a `monitors` array:

```json
"derive": [
  { "name": "total", "value": { "count": "monitors" } },
  { "name": "problems", "value": { "count": "monitors", "where": { "path": "monitor_status", "not": 1 } } },
  { "name": "headline", "value": {
      "if": { "path": "total", "equals": 0 },
      "then": { "template": "No monitor data" },
      "else": { "if": { "path": "problems", "equals": 0 },
                "then": { "template": "All {total} up" },
                "else": { "template": "{problems} of {total} need attention" } }
  } }
]
```

Names are lowercase letters, digits and `_`. An answer that isn't an object is kept under `data`.

## Mapping

`map` is an object whose keys are fields of the card and whose values are rules saying where each one comes from in the answer. A key can reach into the card's own lists: `items[0].value` fills the first fact's value. Card fields have plain names, so a map key never takes quotes, and each field is named once.

A rule can also name the page: [`title_from`](https://legatobar.com/docs/detail-pages.md#titled-by-its-item) reads one against a source's answer for the panel's title row.

Paths are relative to the current JSON value. They support named object fields, dots and zero-based array indexes. They are not full JSONPath expressions or JavaScript: there are no wildcards, recursive searches or executable expressions.

| Response shape | Path or rule |
| --- | --- |
| Nested object | `owner.login` |
| Nested array item | `projects[0].tasks[1].title` |
| First item of a top-level array | `[0].name` |
| Key with spaces or punctuation | `list[0]["Resting HR"]` |
| Entire response, including plain text | `$` |
| List from an array | `{ "each": "projects[0].tasks", "template": "{title}" }` |
| List from a top-level array | `{ "each": "$", "template": "{name}" }` |

Inside `each`, paths are relative to that item and `{$}` means the item itself. Use `owner.login` for a nested field; a leading `$.` is not supported. Field names can contain letters, numbers, underscores and hyphens. Put any other key in quotes and brackets: `list[0]["Resting HR"]` or `["Sleep (h)"]`, for services such as NocoDB and Airtable that name fields the way you title columns. A quoted key can hold spaces, dots and brackets, but not `"`, `\`, `{`, `}` or `|`.

| Rule | Example | Gives |
| --- | --- | --- |
| A path | `"summary.queries.total"` | The value at that path. Paths use dots and `[n]` for array items: `top_blocked.domains[0].domain`. |
| Template | `{ "template": "{summary.clients.active} active clients" }` | Text with `{path}` filled in. A missing value becomes "—". |
| List | `{ "each": "top_blocked.domains", "fields": { "label": "domain", "value": "count" }, "limit": 5 }` | One item per array element, built from `fields` (or one string per element, with `"template"` instead of `fields`, or one list per element, with `"cells"`, for a [table's rows](https://legatobar.com/docs/card-lists.md#table)). Paths inside are relative to the element; `{$}` is the element itself. |
| List of numbers | `{ "each": "data", "where": { "path": "cpu", "gte": 0 }, "value": { "path": "cpu", "scale": 100, "round": 1 }, "buckets": 144 }` | One value per element, from the rule in `value`: a sparkline's `points`. An element the rule gives nothing for is left out, so give the sparkline's `labels` rule the same `where` and `buckets`, and the two stay the same length. `buckets` (2 to 240) keeps at most that many by gathering neighbours into runs of near-equal length: a `value` list averages each run, and a `template` or `fields` list reads its last element. A day of one-minute readings in 144 buckets is one point per 10 minutes. With `"running": true` each number is the total so far, for a month-to-date line; see [Calendar days](https://legatobar.com/docs/mapping-expiry.md#calendar-days). |
| Aggregate | `{ "count": "lights_on" }`, `{ "avg": "monitor_response_time", "of": "monitors" }` | `count` an array, or `sum`, `avg`, `min`, `max`, `first`, `join` or `worst` one field over the array in `of`. `join` takes a `separator` (", " by default). `worst` is the worst state among them: see [Slices of time](https://legatobar.com/docs/mapping-expiry.md#slices-of-time). |
| Condition | `{ "if": { "path": "problems", "equals": 1 }, "then": …, "else": … }` | One rule or the other. Without `else`, nothing when the condition fails. |
| Arithmetic | `{ "add": ["bank_cash", "manual_cash"] }`, `{ "subtract": ["assets", "debts"] }` | `add`, `subtract`, `multiply` or `divide` 2 to 8 sides, each a rule or a number. `subtract` and `divide` go left to right. A side that's missing or not a number, or a division by zero, leaves the result missing, so `default` applies. |
| Month elapsed | `{ "month_elapsed": true }` | How far through this calendar month now is, from 0 to 1: the 24th of a 30-day month is about 0.78. For a pacing card's `elapsed` on a page without a [period](https://legatobar.com/docs/periods.md). |
| Since | `{ "since": "StartedAt" }` | Gives seconds from a moment to now. The input can also be a rule. Reads ISO 8601, Unix seconds or milliseconds. Future moments give negative numbers. Missing or unreadable dates and years before 1970 give no value, so `default` applies. Supports `scale`, `round` and the other adjusters. |
| Expiry | `{ "expires": { "days": "cert_days" }, "warning": 14, "as": "state" }` | A state, words or days for something that expires: see [Expiry](https://legatobar.com/docs/mapping-expiry.md#expiry). |

A list's `each` can also be 2 to 4 paths, joined in order before `where`, `sort` and `limit` apply, for a service that splits one kind of thing across requests. A path among them that holds one object, such as a car's state now, counts as one row, so a story of drives and charges can begin with how the car is now. Lunch Money keeps linked and manual accounts apart; this lists every credit card from both, largest balance first:

```json
{ "each": ["banks.plaid_accounts", "manual.manual_accounts"], "where": { "path": "type", "equals": "credit" },
  "sort": { "by": "to_base", "order": "desc" }, "limit": 20, "fields": { "label": "display_name", "value": "to_base" } }
```

A path with no array in the answer is skipped; with none at all, the card keeps its last value.

Lists and aggregates take the same options for choosing elements:

- `entries`: `true` turns each element that's an object into one row per field, `{ "key", "value" }`, before anything else. See [Names as keys](https://legatobar.com/docs/mapping-tables.md#names-as-keys).
- `lookup`: each element's match in another array, attached as a field before the other options apply. See below.
- `where`: a [condition](https://legatobar.com/docs/mapping-conditions.md#conditions) each element must meet, with paths relative to the element.
- `flatten` and `group`: after `where`, each element's own list in its place, then rows gathered by a value they share. See [Turning a table round](https://legatobar.com/docs/mapping-tables.md#turning-a-table-round).
- `sort`: a path to sort by, or `{ "by": path, "order": "desc" }`. `by` can also be 2 to 4 paths, each breaking the ties of those before it: Todoist's tasks sort by `["section.order_key", "order_key"]`, their section's place and then their own. Rows that tie on every path keep their order.
- `collapse`: after `sort`, a path to a value. A row whose value there is the same as the row kept before it is left out, and so is a row with no value there. Text matches with spaces trimmed and case ignored. Only neighbours count, so scans in Reno, Boise and Reno again keep all three. A map card's [route](https://legatobar.com/docs/card-lists.md#routes) uses it for one stop per place.
- `limit`: how many to keep, from the first.
- `last`: how many to keep, from the end, after `sort` and `collapse`. Use it for the newest rows when they're sorted oldest first. A rule takes `limit` or `last`, not both.

Some services send ids in one answer and the names for them in another. Lunch Money's budget summary lists each category's spending by `category_id`, and its categories request has the names. A `lookup` finds, for each element, the first element of the array in `from` whose `by` field equals the element's `on` field, and attaches it as the field named in `as`:

```json
{ "each": "summary.categories",
  "lookup": { "from": "cats.categories", "by": "id", "on": "category_id", "as": "category" },
  "where": { "path": "category.is_group", "not": true },
  "fields": { "label": { "path": "category.name", "default": "Other" }, "value": "totals.other_activity" } }
```

A renamed category then shows its new name the next time the source answers, with nothing in the page to update. `from` is read from the same place as the array itself: the whole answer for a card's `map` or a derived value. The two ids match as values, so `12` and `"12"` are the same. An element with no match goes without the field, so a `default` applies, and `as` replaces any field the element already had with that name. When `from` is one object rather than an array, it's the only candidate: Mealie's meal plan rows carry a `groupId`, and `"lookup": { "from": "group", "by": "id", "on": "groupId", "as": "group" }` attaches `/api/groups/self` to each, so a row's link can read `group.slug`.



---

# Names and tables

### Names as keys

Some services send a name as the key and its number as the value. AdGuard Home's top domains are `[{"apple.com": 3}, {"google.com": 2}]`: a list of one-field objects, where the domain is the key. `"entries": true` turns each object into rows of `{ "key", "value" }`, so the rest of the rule can read them:

```json
{ "each": "top_queried_domains", "entries": true, "limit": 5,
  "fields": { "label": "key", "value": "value" } }
```

`each` can also name a single object, such as `{"apple.com": 3, "google.com": 2}`, which gives one row per field. `entries` comes first, so `where`, `sort` and `limit` work on the rows it makes. An object's fields have no order of their own, so they come in key order; add a `sort` for any other. Keys with dots, colons or slashes, like `https://dns10.quad9.net:443/dns-query`, stay whole, since `key` is read as a field, not a path.

### Parallel arrays

Open-Meteo sends hourly weather as parallel arrays. Add `"zip": true` to turn them into rows in array order:

```json
{ "each": "hourly", "zip": true,
  "fields": { "label": "time", "values[0]": "temperature_2m" } }
```

For `{"hourly":{"time":["09:00","10:00"],"temperature_2m":[52.1,53]}}`, this makes two columns rows. Use the same rule in `derive` or a card map. `where`, `sort`, `limit` and `buckets` work on the rows as usual.

A null leaves that field missing. For example, null pollen values match `exists: false`. Fields that are not arrays are ignored. Unequal arrays stop at the shortest array. `zip` needs one `each` path and cannot be combined with `entries`.


### Names and exact times

`{record|first_word}` takes the first whitespace-separated word. `{record|rest_words}` takes the remaining text, with surrounding whitespace removed. Spaces and tabs both separate the first word; the remaining names stay together. For a local DNS record such as `192.0.2.10 printer.example`, these give the address and hostname. Derive the name first, then sort rows by it.

`{time|time}` draws an exact local 24-hour clock time with seconds, such as `17:03:12`, from Unix seconds or a supported date. It stays fixed as an answer ages, making it useful for query logs. Include the date separately when showing older history. The `hour` filter includes a zone on a repeated daylight-saving hour so the two hours have different labels.

### Turning a table round

Some services answer one way round when a chart wants the other. Lunch Money's budget summary lists each category with its months inside it; a [`columns`](https://legatobar.com/docs/card-numbers.md#columns) chart of income against spending wants each month with its categories. Two options do it, after `where` and before `sort`:

- `flatten`: a path to each element's own list, which takes the element's place. Each item of that list gets the element it came from as `parent`, so it can still be told apart. Items that aren't objects are left out. A GitHub contribution calendar's weeks flatten into its days for a [heatmap](https://legatobar.com/docs/card-time.md#heatmap). An object at the path gives its fields as `{key, value}` rows, for a service that sends each slot's counts by name: Pi-hole's clients over time, `{"timestamp": …, "data": {"192.0.2.10": 41}}`, flatten into one row per client per slot.
- `group`: a path to a value the rows share. One row per value, in the order each first appears, as `{ "key", "count", "rows" }`. `sort`, `limit` and `fields` then work on the groups, and an aggregate with `"of": "rows"` totals each one.

A field's name can be a path into a list the card takes, so `values[0]` and `values[1]` fill a column's two values. This is the chart on the Net Worth example: income from income categories, spending from the rest, January to this month:

```json
{ "each": "summary.categories",
  "lookup": { "from": "cats.categories", "by": "id", "on": "category_id", "as": "category" },
  "where": { "all": [ { "path": "category.is_group", "not": true }, { "path": "category.exclude_from_totals", "not": true } ] },
  "flatten": "occurrences", "group": "start_date",
  "fields": {
    "label": { "template": "{key|month}" },
    "values[0]": { "add": [ { "sum": "other_activity", "of": "rows", "where": { "path": "parent.category.is_income", "equals": true } },
                            { "sum": "recurring_activity", "of": "rows", "where": { "path": "parent.category.is_income", "equals": true } } ],
                   "scale": -1, "round": 0 },
    "values[1]": { "add": [ { "sum": "other_activity", "of": "rows", "where": { "path": "parent.category.is_income", "not": true } },
                            { "sum": "recurring_activity", "of": "rows", "where": { "path": "parent.category.is_income", "not": true } } ],
                   "round": 0 } } }
```

`summary` here is `/v2/summary?start_date={date.year_start}&end_date={date.month_end}&include_occurrences=true`, and `cats` is `/v2/categories?format=flattened`.

`min` and `max` also take `rank`, a list of values from best to worst, for values whose order isn't numeric. Uptime Kuma's status is 1 up, 3 maintenance, 2 pending, 0 down, so `{ "max": "monitor_status", "of": "monitors", "rank": [1, 3, 2, 0] }` is the worst status of any monitor.

Any rule can then be adjusted:

| Option | Example | Does |
| --- | --- | --- |
| `values` | `{ "path": "blocking.blocking", "values": { "enabled": "ok", "disabled": "warning" } }` | Looks the value up. Entries are literal values or an object containing only `{ "template": … }`; other rule objects are not evaluated here. |
| `default` | `"default": "unknown"` | Used when there's no value, or no `values` entry for it. Like a lookup entry, it can be a literal or a sole `template` object. |
| `match` | `{ "path": "config.data.meta", "match": "ctime=([0-9]+)" }` | Searches the value's text with a regular expression and keeps the first capture group (or the whole match without one), as a number when it reads as one: `creation-qemu=11.1.3,ctime=1793983411` → 1793983411. It comes before `values`, `scale` and `round`; no match is no value, so `default` applies. Page-authored `match` patterns stop after a short execution budget; inputs above 65,536 UTF-16 code units are not matched. A budget limit acts like no match, so the rule’s `default` applies. Parameter patterns use the same budget and refuse a value on timeout. |
| `clock` | `{ "path": "[\"Sleep start\"]", "clock": 12, "round": 2 }` | A moment (ISO 8601, Unix seconds, or a date and time like `2026-10-29 22:56:24 -0500`) as hours of the day on this Mac: 10:56 PM is 22.93. Times before this hour (0–23) are the next day's and count from 24, so with `12` a wake-up at 8:01 AM is 32.02 and a night stays in order. For a [ranges](https://legatobar.com/docs/card-numbers.md#ranges) card with `unit` `clock`. Applied before `scale`. |
| `scale`, `offset`, `round` | `{ "path": "climate_state.inside_temp", "scale": 1.8, "offset": 32, "round": 0 }` | Scaled, then offset, then rounded to that many decimals: here, °C to °F. |

Template placeholders take filters after a `|`, and filters chain:

| Filter | Example | Gives |
| --- | --- | --- |
| `title`, `upper`, `lower` | `{state\|title}` | "not_home" → "Not home" |
| `round`, `round:n` | `{temp\|round:1}` | 73.46 → "73.5" |
| `percent`, `percent:n` | `{monitor_uptime_ratio_1d\|percent}` | 0.9965 → "99.7%" |
| `duration`, `duration:unit` | `{blocking.timer\|duration}` | 299 seconds → "4m 59s". A unit reads other times: `ticks` (100 ns, so 10,000,000 a second, as Jellyfin and Emby count), `ms`, `s` (the default) or `min`: `{NowPlayingItem.RunTimeTicks\|duration:ticks}` is 70,800,000,000 → "1h 58m". |
| `timecode`, `timecode:unit` | `{PlayState.PositionTicks\|timecode:ticks}` | A player's clock, rounded down to the second: "1:42:10", "42:05" under an hour, "0:07". Takes the same units as `duration`. A negative time reads "0:00", and text that isn't a number passes through, as with `duration`. |
| `pad:n` | `S{ParentIndexNumber\|pad:2}E{IndexNumber\|pad:2}` | A whole number zero-padded to n digits (1–4): 2 and 5 → "S02E05". Longer numbers aren't cut; anything that isn't a whole number passes through unchanged. |
| `clip:N` | `{overview\|clip:80}` | Shorten text to at most N characters (1 to 500), including the ellipsis. Prefer a word boundary in the last 20 characters. Trim trailing spaces and punctuation. Shorter text stays unchanged. |
| `until` | `{blocking.timer\|until}` | The clock time that many seconds from now: "2:00 PM" |
| `from_now` | `{choice\|from_now}` | The moment that many seconds from now, in ISO 8601 UTC: 3600 → "2026-11-17T21:41:05Z". For a button's request, such as a silence's end; see [Buttons](https://legatobar.com/docs/buttons.md). |
| `month` | `{start_date\|month}` | The month of a date, short: `2026-10-01` → "Oct". |
| `month_year` | `{published\|month_year}` | The month and year of a date: `2026-11-18` → "Nov 2026". For a date that should read the same next year, such as a release's. |
| `date` | `{Date\|date}` | A date, short: `2026-10-31` → "Oct 31", with no "Today" and no year. For columns by day across a month, where every column needs a label of its own. |
| `compass` | `{wind_deg\|compass}` | Degrees as one of the eight points of the compass: 200 → "S", 315 → "NW". |
| `hour` | `{dt\|hour}` | "Now" for this hour, then the hour short: "11P", "1A", "12P". For a forecast's columns. |
| `hour:plain` | `{dt\|hour:plain}` | The hour short, this one too: "12P" where `hour` says "Now". For a chart of the last 24 hours, whose last column is still filling. |
| `clock`, `clock_hour` | `{time\|clock}` | A moment's time of day as this Mac's clock shows it: "6:12 PM" (or "18:12"), and with `clock_hour` just its hour, "6 PM". For a chart's labels, since unlike `ago` they don't change as time passes: `{time\|weekday} {time\|clock_hour}` is "Tue 2 PM". |
| `bytes` | `{usage\|bytes}` | A count of bytes in the unit that suits it, 1,024 to the next and written as people say sizes: 14,195,561 → "13.5 MB", 462,773,288,960 → "431 GB", 4,617,948,836,659 → "4.2 TB". One decimal under 100, none from 100. Text that isn't a number passes through. |
| `plain` | `{__search_hit__.highlights\|plain}` | An HTML snippet as words, such as a search hit's excerpt: `Home <b>insurance</b>,` → "Home insurance,". Tags that mark words (`b`, `i`, `em`, `span`, `mark` and the like) go with no space; any other tag, and each run of spaces and line breaks, becomes one space. `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&apos;`, `&nbsp;` and numeric entities are decoded once, after the tags are gone. Nothing is drawn or loaded. |
| `verbatim` | `{title\|clip:160\|verbatim}` | Text exactly as the service sent it, for a field that takes inline formatting: a list item's text or a text card's body. `__init__()` keeps its underscores, and `[docs](https://…)` stays as words, with no link. It puts a backslash before each ASCII punctuation mark, which the formatting hides; anywhere else the backslashes show. It goes last, after `clip` or any other filter. |
| `ceil` | `legato://page/pihole-queries?at={time\|ceil}` | A number rounded up to a whole one: a moment with fractions of a second, `1795624370.4`, as the Unix second `1795624371`, so a link's "up to this second" includes it. |
| `ms` | `{reply.time\|ms}` | Seconds read as a reply time: `0.00012` is `0.1 ms`, `0.0123` is `12 ms` and `1.24` is `1.2 s`. Under a tenth of a millisecond it's `<0.1 ms`. |
| `host` | `{address\|host}` | An address's host alone: `https://raw.example.com/lists/pro.txt` is `raw.example.com`. |
| `file` | `{address\|file}` | The last part of an address's path: `pro.txt`. With `host`, a name for a list that has none of its own. |
| `raw` | `https://my.lunchmoney.app/transactions?transaction_id={id\|raw}` | A number exactly as the service sent it, with no thousands separators: 2528490123 stays `2528490123`, not "2,528,490,123". For an id in a link. Text passes through unchanged. |
| `origin` | `{monitor_url\|origin}` | An address's scheme, host and port, without its path: `https://glance.example.com/api/healthz` → `https://glance.example.com`. For a link to the app a health check watches. |
| `weekday` | `{dt\|weekday}` | "Today", then the short weekday: "Thu". For a forecast's rows. |
| `day` | `{date_expected\|day}` | The day a date falls on, as you'd say it: "Today", "Tomorrow", "Yesterday", then "Sat, Oct 31" (with the year when it isn't this one). For when something is due or expected. |
| `ago` | `{published\|ago}` | How long ago an ISO 8601 date or Unix time was: "now", "5m ago", "2h ago", "3d ago", then the date ("Oct 12"). A date with no time, like `2026-10-12`, counts from that day's midnight on the Mac. Worked out when the source answers. |
| `in` | `{dt\|in}` | How far ahead a moment is: "now", "in 12m", "in 2h", "in 3d", then the date after a week. Past moments say "now". Reads the same dates as `ago`. Worked out when the source answers. |

`ago`, `month`, `month_year`, `day`, `weekday` and `hour` read Unix time (seconds, or milliseconds as Tesla sends them), ISO 8601, a plain date (`2026-10-31`) or a date and time with no zone (`2026-10-31 14:30:00`, as Parcel sends them). The last two are read as the Mac's own time, so a date isn't the evening before when you're west of Greenwich.

Numbers are formatted for reading: `104628` becomes "104,628".



---

# Expiry and slices of time

### Expiry

Certificates, domains, subscriptions and keys expire. `expires` reads how many days are left (`days`) or when it expires (`date`), and `as` says what it gives:

- `state`: `ok`; `warning` from `warning` days left (14 by default); `critical` from `critical` days left (0 by default, so due today) and once it has expired. `unknown` when there's no input, unless the rule has its own `default`.
- `text`: "Expires today", "Expires tomorrow", "9 days left"; "Expired today", "Expired yesterday", "Expired 3 days ago".
- `days`: whole days left. 0 is today, whether it expires later today or expired earlier today; negative from the day after.

```json
{ "expires": { "days": "monitor_cert_days_remaining" }, "warning": 14, "as": "state" }
{ "expires": { "date": "renews_at" }, "as": "text" }
```

- **Days** are calendar days on this Mac, from today to the day it expires, as the `day` filter says "Tomorrow". A certificate expiring at 2 AM UTC on 9 November expires today on the 8th in New York.
- **`days`** is a number, or text that reads as one (`"12"`). A fraction counts toward zero: 13.9 is 13 days left, and -0.4 expired today.
- **`date`** is read as the [`date` rule](https://legatobar.com/docs/history-dates.md#dates) reads dates: Unix time, ISO 8601, a plain date, a date and time with no zone (as this Mac's time), carriers' words, and a feed's dates. A date with no time is good through that day; a moment has gone once it's now.
- **`warning` and `critical`** are whole days from 0 to 3650, and `critical` is no more than `warning`.
- **A missing input**, or one that isn't a number or a real date (`2026-02-30` isn't), gives nothing, so `default` applies.
- **When it's worked out:** a card's `map` works it out each time the page is drawn, and `derive` when the source answers. When the day changes, pages draw again and a source whose `derive` counts to a date is read again.
- It can't be used in a history source's [`row`](https://legatobar.com/docs/history-reading.md#only-what-the-page-needs-row), since a kept value can't follow the days as they pass. Name its input in `row` and use it in `derive`.

A token's own expiry date can come from Settings → Secrets rather than the service: give the source `"secret_expires": "token_expires"` and read `token_expires` like any date. Put the rule in the card's `map` and `when`, not `derive`, so the days keep counting while the service doesn't answer. A card that warns only in the token's last 14 days, and a note while no date is saved:

```json
{ "id": "token", "type": "status", "label": "API access token", "state": "unknown",
  "source": { "ref": "api",
              "when": { "value": { "expires": { "date": "token_expires" }, "as": "state" }, "in": ["warning", "critical"] },
              "map": { "state": { "expires": { "date": "token_expires" }, "as": "state" },
                       "detail": { "expires": { "date": "token_expires" }, "as": "text" } } } }
{ "id": "token-date", "type": "text", "body": "Add the token's expiry date in Settings → Secrets.",
  "source": { "ref": "api", "when": { "path": "token_expires", "exists": false } } }
```

Uptime Kuma sends `monitor_cert_days_remaining` for HTTPS monitors only, so a fleet's state gives a `default` of `ok`, or every other monitor would be `unknown`. A certificate with 0 days left is `critical` (red), as is an expired one. An invalid certificate isn't an expiring one, so that keeps its own test:

```json
"state": { "if": { "path": "monitor_cert_is_valid", "equals": 0 },
           "then": { "template": "critical" },
           "else": { "expires": { "days": "monitor_cert_days_remaining" }, "as": "state", "default": "ok" } }
```

A list of certificates, soonest first:

```json
"items": { "each": "monitors", "where": { "path": "monitor_cert_is_valid", "in": [0, 1] },
           "sort": "monitor_cert_days_remaining", "limit": 4,
           "fields": { "label": "monitor_name",
                       "value": { "expires": { "days": "monitor_cert_days_remaining" }, "as": "text" } } }
```

A card that shows only while a certificate needs attention tests `"not": "ok"`. A missing field is `unknown`, so it shows the card too; `"equals": "critical"` would hide it.

```json
"when": { "value": { "expires": { "days": "cert_days" }, "as": "state" }, "not": "ok" }
```

### Slices of time

`keep` beside `buckets` chooses what each run keeps. A value list takes `"max"`, `"min"`, `"sum"`, `"average"` or `"last"`. The default is average. A template or fields list takes `{"max":"path"}` or `{"min":"path"}` to keep the row with the highest or lowest number at that path. Ties keep the earlier row. A row with no number there loses to one that has one. The default is the last row. For rain, `{"each":"one.minutely","value":"precipitation","buckets":12,"keep":"max"}` keeps a five-minute shower that an average would flatten.

`buckets` gathers rows by count, which suits a steady series. For a strip of an item's [samples](https://legatobar.com/docs/history-collect.md#samples), where an hour with no sample has to show as one, add `by_time`: the span is cut into `buckets` equal slices of time, and each row goes in the slice its time falls in.

```json
"segments": { "each": "kept.rows", "by_time": { "at": "at", "span": "kept.span" }, "buckets": 96,
              "fields": { "state": { "worst": "row.state", "of": "rows" }, "label": { "template": "{from|time}" } } }
```

- **`by_time`** is `{ "at": path, "span": path }`: where each row's time is, and where the answer has the span, an object with `from` and `until`. A dataset source of samples answers with both: each row's `at` and `kept.span`. Times are ISO 8601 (as samples are), Unix seconds, or any instant the [date rules](https://legatobar.com/docs/history-dates.md#dates) read.
- **`span`** can also be written out, `{ "from": …, "until": … }`, in Unix seconds or instants: the page's own period, `{ "from": "{period.start_unix}", "until": "{period.end_unix}" }`, for an answer that doesn't say its span. With `"keep": "sum"` and `value`, an empty slice is 0 rather than nothing, so a count over time keeps every slice: one series per client from Pi-hole's clients over time.
- **`last_hours`** in place of `span` makes the span the last that many whole hours (1 to 168), ending with the one this is, one slice an hour unless `buckets` says. For a log the service answers as rows, such as an hour-by-hour strip of one domain's queries over a day: `"by_time": { "at": "time", "last_hours": 24 }`.
- **Every slice is made,** empty or not, oldest first, and each is `{ "from", "until", "count", "rows" }`: `fields` and `template` read the slice, so `count` is its rows and an aggregate `"of": "rows"` reads them. A row whose time is outside the span, or at its `until`, is left out.
- **`buckets`** is 2 to 240 slices; without it, `by_time` makes 144, ten minutes each of a day. A [strip](https://legatobar.com/docs/card-time.md#strip) takes up to 240, so a day of 5-minute samples (288) needs slices of at least two of them.
- **`value`** averages each slice's numbers, and an empty slice gives nothing, so a [sparkline](https://legatobar.com/docs/card-numbers.md#sparkline) of the same rows closes its gaps up as sparklines do. The strip draws them.
- `where` applies first. `by_time` doesn't take `group`, `sort`, `limit`, `last`, `collapse`, `flatten`, `entries` or `lookup`: its slices are in time order, each one there.

**`worst`** is the worst state among rows: `{ "worst": "row.state", "of": "rows" }`. States rank `ok`, `off`, `unknown`, `warning`, `critical`, so a slice with one `critical` sample is `critical`. A row whose value is missing, or isn't one of these, counts as `unknown`, and no rows at all gives `none`, the strip's empty slice. `off` ranks above `ok` here (the page's status counts it as `ok`), so a slice where a guest was off shows that it was.

### Calendar months

`by_month` makes one slice per calendar month instead: the last `months` months up to this one, oldest first, each one there whether it has rows or not. It's for a service that leaves out months with nothing in them, such as Immich's photos per month, so a columns card still shows a month with none.

```json
"items": { "each": "buckets", "by_month": { "at": "timeBucket", "months": 12 },
           "fields": { "label": { "template": "{from|month}" }, "values[0]": { "sum": "count", "of": "rows" } } }
```

- **`by_month`** is `{ "at": path, "months": 1 to 36 }`: where each row's time is, and how many months, the current one last.
- **Each month** is `{ "from", "until", "count", "rows" }`: `from` is its first day and `until` the next month's, as plain dates (`2026-11-01`), so `{from|month}` gives "Nov". `count` is its rows, and an aggregate with `"of": "rows"` reads them; a `sum` over a month with no rows is 0.
- **A plain date or month, or a time with no zone** (`2026-11-01`, `2026-11`, `2026-11-06T16:46:00`) counts in the month it's written in. A moment with a zone, or Unix seconds, is read in the Mac's time zone, so a photo at 00:30 UTC on 1 December is November's in Chicago.
- `where` applies first. `by_month` doesn't take `buckets`, `by_time`, `group`, `sort`, `limit`, `last`, `collapse`, `flatten`, `entries` or `lookup`.

### Calendar days

`by_day` makes one slice for each calendar day from `from` through `through`, oldest first, each one there whether it has rows or not. It's for charting each day from a service that lists events rather than days, such as Stripe's payments: columns for the last week, or a line through the days of the page's [period](https://legatobar.com/docs/periods.md#periods) (a columns card takes 48 at most).

```json
"items": { "each": "moves.data", "where": { "path": "type", "equals": "charge" },
           "by_day": { "at": "created", "from": "{date.days_ago_6}", "through": "{date.today}" },
           "fields": { "label": { "template": "{from|weekday}" }, "values[0]": { "sum": "amount", "of": "rows" } } }
```

- **`by_day`** is `{ "at": path, "from": day, "through": day }`. Each day is a plain date (`2026-11-01`) or one token: `{period.start}` and `{period.end}` on a page with a period, or a [date token](https://legatobar.com/docs/source-requests.md#dates-in-requests) such as `{date.days_ago_29}` and `{date.today}`. They're worked out as the rule runs, so the chart moves with the period and the calendar. Both days are included, up to 400 days.
- **Each day** is `{ "from", "until", "count", "rows" }`: `from` is the day and `until` the next, as plain dates, so `{from|date}` gives "Nov 3" and `{from|weekday}` "Tue". A `sum` over a day with no rows is 0.
- **A plain date, or a time with no zone,** counts on the day it's written. A moment with a zone, or Unix seconds, is read in the Mac's time zone, so a payment at 02:00 UTC on 4 November is the 3rd's in Chicago. A service's own dashboard may count days in another zone.
- A day with no rows looks the same as a quiet day. When the list behind it may be cut short (a [list across pages](https://legatobar.com/docs/source-requests.md#a-list-across-pages) that stopped at its `max`), say so on the card, since its earliest days would look empty.
- **A running total** draws a month so far, as Stripe's own dashboard does: derive the days with their totals, then list those with `"running": true`, which makes each number itself plus every one before it. A day with nothing adds nothing, so the line stays level.

  ```json
  "derive": [ { "name": "days", "value": { "each": "moves.data", "by_day": { "at": "created", "from": "{period.start}", "through": "{period.through}" },
                                           "fields": { "day": "from", "gross": { "sum": "amount", "of": "rows" } } } } ]
  ```
  ```json
  "points": { "each": "days", "value": "gross", "running": true }, "labels": { "each": "days", "template": "{day|date}" }
  ```

- `where` applies first. `by_day` doesn't take `buckets`, `by_time`, `by_month`, `group`, `sort`, `limit`, `last`, `collapse`, `flatten`, `entries` or `lookup`.



---

# Conditions

<a id="conditions"></a>

Conditions appear in `where`, `if` and a button's `when`. Each has a `path` (or a `value`, which is any rule) and one test: `equals`, `not`, `in` (a list), `not_in`, `gt`, `gte`, `lt`, `lte`, `contains`, `in_list` (a [list](https://legatobar.com/docs/lists.md#lists) in Settings → Lists) or `exists`. `"1"` and `1` count as equal, and a missing value meets `not`.

`exists: true` holds when there's a value, and `exists: false` when there's none. Null counts as none, as GitHub's `"latestRelease": null` says there's no release; `""`, `0`, `false` and an empty list are values. Use it rather than `not: null`, which a missing value also meets, so it holds for every answer. Unlike the other tests it always has an answer, so a card's `when` never shows the can't-say note for it. This names the latest release, or None:

```json
{ "if": { "path": "latestRelease.tagName", "exists": true }, "then": "latestRelease.tagName", "else": { "template": "None" } }
```

`contains` holds for text that has the given text in it (case matters), or a list with an item equal to it: a guest tagged `docker;homelab` contains `homelab`.

`in_list` names a [list](https://legatobar.com/docs/lists.md#lists) kept in Settings → Lists, and holds when the value contains any of its entries. Case, accents and punctuation don't matter, and an entry matches only whole words: "Hill" matches "Fernhollow Hill, ST" but not "Hillside". Add `"if_missing": true` to make the test hold when the list is missing or empty, and `"optional": true` when the page works fine without the list, so its cards don't ask you to add it. This counts the deliveries whose delivered place is in the list `delivery-area`:

```json
{ "count": "deliveries", "where": { "path": "location", "in_list": "delivery-area" } }
```

- Like other tests, it can take a `value` (any rule) in place of `path`.
- A list that doesn't exist or has no entries makes the condition false, and the page says "Add the list delivery-area in Settings → Lists" (or "Add entries to the list delivery-area in Settings → Lists").
- It can't be used in a history source's [`row`](https://legatobar.com/docs/history-reading.md#only-what-the-page-needs-row), since a list can change in Settings and a kept value can't know. Use it in `derive`.

`equals`, `not`, `gt`, `gte`, `lt`, `lte` and `contains` can compare with another value in the same answer instead of one written in the page: give `{ "path": "…" }` in its place. In a `where`, that path is in the same row; `{ "answer": "…" }` reaches outside it, into the whole answer, such as the backups made since a guest was created: `"where": { "path": "ctime", "gte": { "answer": "created" } }`. An `if` in a row's `fields` reaches the whole answer the same way, to mark the row that matches something else in it. This counts the packages whose candidate version isn't the installed one, from Proxmox's `apt/versions`:

```json
{ "count": "versions.data", "where": { "all": [ { "path": "CurrentState", "equals": "Installed" },
                                               { "path": "Version", "not": { "path": "OldVersion" } } ] } }
```

When the other path has nothing there, the condition can't say, as when the tested path has nothing: a card's `when` shows the card with a note, and `where`, `if` and buttons count it as false (a missing value still meets `not`).

To test more than one thing, put 2 to 8 conditions in `all` (every one must hold) or `any` (at least one must). They nest. This lists credit cards that don't round to $0:

```json
"where": { "all": [ { "path": "type", "equals": "credit" }, { "value": { "path": "to_base", "round": 0 }, "not": 0 } ] }
```

Conditions also decide whether a whole card shows: see [Cards that show on a condition](https://legatobar.com/docs/mapping-conditions.md#cards-that-show-on-a-condition).

### Cards that show on a condition

For help choosing the structure, see [Page design](https://legatobar.com/docs/design.md#choose-the-right-structure), including a [linked overview and detail example](https://legatobar.com/docs/design.md#a-linked-overview-and-detail-example).

A card's `when` shows it only while a condition holds in its source's answer, the derived values before `map`. A page can then stay quiet and show only the exceptions: a door left open, water running, blocking turned off. Linked to a page with the details, an exception is one click from them.

```json
{ "id": "garage", "type": "status", "label": "Garage door open", "state": "warning", "url": "legato://page/security",
  "source": { "ref": "house", "when": { "path": "garage", "equals": "open" } } }
```

- **True:** the card shows. **False:** it's hidden, with its buttons. It doesn't count toward the page's status or notify. Notifications quietly count it as OK again (no "Back to OK", since a condition turning false isn't a recovery), so a warning card, or a fleet's item, that comes back notifies each time.
- **The answer can't say:** nothing or null at a path the condition tests, or a comparison (`gt`, `lt`, …) with something that isn't a number, like `"unavailable"` (`exists` always has an answer). The card shows, with a note saying so, so a field the service stopped sending can't quietly hide an alert. This is stricter than `where`, `if` and a button's `when`, where a missing value meets `not` and a comparison that can't be made is false.
- **Before the first answer**, the card waits as any sourced card does. **After a failed fetch**, the last answer decides, so the card keeps the visibility it had, and the source goes on polling while the card is hidden, so it can come back. If cards are hidden behind a source that's failing, a notice appears above the page’s sections and tabs ("… couldn't be reached, so cards here that show only on a condition may be out of date", or "… reported an error, …" when the source's `fail` turned the answer down). It stays visible when a section is collapsed or another tab is selected.
- **What's left:** a heading whose section had cards and shows none hides too. A tab whose cards are all hidden says "Nothing to show right now." (the tabs stay where they are), and a tabs card with nothing in any tab hides. A page with nothing left says so.
- A misspelled or malformed condition is an error on the card, not a hidden card. `when` goes on each card that uses it, not on a shared source. A card with `when` may leave out `map`, or give an empty one; `map` is otherwise an object with at least one field.

Paths, rules and filters are all there is: a source never runs code on your Mac.



---

# Sparkline readings

<a id="sparkline-readings"></a>

Some services only report a value as it is now, like a net worth or a battery level. A sparkline's `points` can be a `history` rule instead: the Mac records the rule's number each time the source answers and draws the readings it has kept.

```json
{ "id": "trend", "type": "sparkline", "label": "Net worth, 60 days", "unit": "USD",
  "source": { "ref": "money", "map": { "points": { "history": "net", "every": "1d", "keep": 60 } } } }
```

| Setting | | |
| --- | --- | --- |
| `history` | required | A [rule](https://legatobar.com/docs/mapping.md#mapping) giving a number, here the derived `net`. |
| `every` | optional | One reading per period, `1d` by default, at least `1m`. A later reading in the same period replaces the earlier one, so with `1d` the day's last answer is its point. Days start at midnight on the Mac. |
| `keep` | optional | How many readings to keep, the newest, from 2 to 60. Default 60. |

Until there are two readings, the card says it's collecting them. Only a sparkline's `points` take a history rule. The card's `labels`, `start_label` and `end_label` come from the readings' times unless the page sets them, each point labelled the way the ends are: with `1d` or longer, the first reading's date ("Oct 28") and "Today" (or the last reading's date when it wasn't today); more often, the first reading's time and "Now" while the last reading is at most one and a half periods old, each with its date when it isn't today's. They stay true on their own: at midnight, and when "Now" runs out, the card is drawn again from the readings kept, without asking the service. A lowered `keep` drops the oldest readings, and their labels, at once.

### Another page's readings

A home page can show readings another page keeps, as they are, without recording them again: `{ "history_of": "net-worth#trend.points" }` names the page id, the card and its `points`. The chart opens with every reading that card has, and the other page goes on recording them. `every` (default `1d`) says how far apart they are, for the labels, and `keep` (2–60) how many of the newest to show. The card says it's collecting readings until that history has two.

```json
{ "id": "worth", "type": "sparkline", "label": "Net worth", "unit": "USD",
  "source": { "ref": "money", "map": { "points": { "history_of": "net-worth#trend.points", "keep": 30 } } } }
```

The readings are kept on the Mac, not in the page file, so rewriting the page keeps them, and each Mac has its own. They're kept in History's database, listed in **Settings → History** under "Sparkline readings" by page, with **Export…** and **Delete…** for each page, and included in **Export history…**. They're removed five minutes after their page leaves the Pages folder. They start when the rule is added: there's nothing to backfill from, and the Mac records only while Legato is running and the source answers.

Use `history_of` to show a sparkline's numbers on another page. To collect and query whole rows across pages, use a dataset. See [History](https://legatobar.com/docs/history.md).


---

# Worked examples

<a id="worked-examples"></a>

Each example is a complete small page. Connection settings live once under `sources`, and each card has only `ref` and `map`. The [example pages](https://legatobar.com/docs/source-examples.md#example-pages) add more cards and controls.

### A feed: the latest posts, each linking to its page

Any blog, news site or release page with an RSS, Atom or JSON feed works with `"format": "feed"`. The answer is the same shape for all three: the feed's `title` and `url`, a `count`, and `items` in the feed's order (newest first, in almost every feed; a feed of more than 200 keeps its 200 newest), each with `title`, `url`, `published` (ISO 8601, UTC), `author`, `summary` (plain text, up to 300 characters) and `id` when the entry has them.

A [`list`](https://legatobar.com/docs/card-lists.md#list) card's rows can be objects with a link and a detail, so each post opens when it's clicked:

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "Apple Developer News",
  "icon": "newspaper",
  "sources": {
    "news": {
      "url": "https://developer.apple.com/news/rss/news.rss",
      "auth": { "type": "none" },
      "format": "feed",
      "every": "1h"
    }
  },
  "cards": [
    { "id": "latest", "type": "list", "label": "Latest",
      "source": { "ref": "news",
                  "map": { "items": { "each": "items", "limit": 8,
                                      "fields": { "text": "title", "url": "url",
                                                  "detail": { "template": "{published|ago}" } } } } } }
  ]
}
```

`{published|ago}` puts "2h ago" at each row's right; a post without a date gets a dash. For newest first in a feed that isn't, add `"sort": { "by": "published", "order": "desc" }`.

An address that answers with a web page rather than a feed fails with "didn't send an RSS, Atom or JSON feed": use the feed's own address, usually linked from the site as RSS or found at `/feed`, `/rss` or `/atom.xml`.

A feed that arrives cut off, or with broken XML, fails with "stopped partway through" or "has an XML error on line N"; the card keeps what it last showed and tries again at the next refresh.

### Several feeds in one place: tabs

A [`tabs`](https://legatobar.com/docs/card-text.md#tabs) card shows one of its tabs at a time, so several feeds share the room one takes. Each card in a tab has its own `source`, just as a card on the page does; the `tabs` card itself has none. [Examples/pages/reading.json](https://legatobar.com/examples/reading.json) puts Hacker News, Apple's developer news and the Swift blog in three tabs:

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "Reading",
  "icon": "newspaper",
  "sources": {
    "hn": { "url": "https://hnrss.org/frontpage", "auth": { "type": "none" }, "format": "feed", "every": "30m" },
    "apple": { "url": "https://developer.apple.com/news/rss/news.rss", "auth": { "type": "none" }, "format": "feed", "every": "1h" },
    "swift": { "url": "https://www.swift.org/atom.xml", "auth": { "type": "none" }, "format": "feed", "every": "6h" }
  },
  "cards": [
    { "id": "feeds", "type": "tabs",
      "tabs": [
        { "label": "Hacker News",
          "cards": [
            { "id": "hn", "type": "list", "label": "Front page", "style": "numbered",
              "source": { "ref": "hn",
                          "map": { "items": { "each": "items", "limit": 10,
                                              "fields": { "text": "title", "url": "url", "detail": { "template": "{published|ago}" } } } } } }
          ] },
        { "label": "Apple",
          "cards": [
            { "id": "apple", "type": "list", "label": "Developer news",
              "source": { "ref": "apple",
                          "map": { "items": { "each": "items", "limit": 8,
                                              "fields": { "text": "title", "url": "url", "detail": { "template": "{published|ago}" } } } } } }
          ] },
        { "label": "Swift",
          "cards": [
            { "id": "swift", "type": "list", "label": "Swift.org blog",
              "source": { "ref": "swift",
                          "map": { "items": { "each": "items", "limit": 8,
                                              "fields": { "text": "title", "url": "url", "detail": { "template": "{published|ago}" } } } } } }
          ] }
      ] }
  ]
}
```

Every source keeps polling whichever tab is showing, so a status card in a tab out of sight still counts toward the page's status and notifies. Buttons and row actions go on the cards in the tabs, as they would on the page.

### Pi-hole v6: a sign-in and three requests

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "Pi-hole",
  "sources": {
    "pihole": {
      "url": "http://pi.hole",
      "secret": "pihole",
      "every": "1m",
      "auth": {
        "type": "login",
        "request": {
          "method": "POST",
          "path": "/api/auth",
          "body": {
            "password": "{secret}"
          }
        },
        "token": "session.sid",
        "send": {
          "header": "X-FTL-SID"
        },
        "logout": {
          "method": "DELETE",
          "path": "/api/auth"
        }
      },
      "requests": {
        "summary": "/api/stats/summary",
        "blocking": "/api/dns/blocking",
        "top_blocked": "/api/stats/top_domains?blocked=true&count=10"
      }
    }
  },
  "cards": [
    {
      "id": "queries",
      "type": "stat",
      "label": "Queries today",
      "source": {
        "ref": "pihole",
        "map": {
          "value": "summary.queries.total"
        }
      }
    }
  ]
}
```

The secret can be an app password from Pi-hole's Settings → Web interface / API. [Pi-hole in your Mac's menu bar](https://legatobar.com/services/pi-hole) has five linked pages built this way, sharing one sign-in, with a button to pause and resume blocking, and how to set them up.

### Uptime Kuma: metrics grouped per monitor

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "Home lab",
  "sources": {
    "kuma": {
      "url": "https://kuma.example.com",
      "secret": "kuma",
      "every": "1m",
      "auth": {
        "type": "basic"
      },
      "requests": {
        "monitors": {
          "path": "/metrics",
          "format": "prometheus",
          "group_by": "monitor_id",
          "split_by": [
            "window"
          ]
        }
      },
      "derive": [
        {
          "name": "problems",
          "value": {
            "count": "monitors",
            "where": {
              "path": "monitor_status",
              "not": 1
            }
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "services",
      "type": "fleet",
      "label": "Services",
      "source": {
        "ref": "kuma",
        "map": {
          "items": {
            "each": "monitors",
            "where": {
              "path": "monitor_type",
              "not_in": [
                "push",
                "dns",
                "group"
              ]
            },
            "fields": {
              "name": "monitor_name",
              "state": {
                "path": "monitor_status",
                "values": {
                  "1": "ok",
                  "0": "critical",
                  "2": "warning",
                  "3": "off"
                },
                "default": "unknown"
              },
              "detail": {
                "template": "{monitor_response_time} ms · {monitor_uptime_ratio_1d|percent} in 24 hours"
              }
            }
          }
        }
      }
    }
  ]
}
```

The secret is an API key from Kuma's Settings → API Keys. Once Kuma has an API key, it accepts only keys.

### Home Assistant: one template for the whole page

Rather than download every entity, ask Home Assistant to render one small JSON answer with exactly what the page needs:

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "Home",
  "sources": {
    "home": {
      "url": "http://homeassistant.local:8123/api/template",
      "secret": "home-assistant",
      "every": "1m",
      "method": "POST",
      "body": {
        "template": "{{ {\"kitchen\": states('light.kitchen_main_lights'), \"lights_on\": states.light | selectattr('state','eq','on') | map(attribute='name') | list} | tojson }}"
      }
    }
  },
  "cards": [
    {
      "id": "kitchen",
      "type": "stat",
      "label": "Kitchen",
      "source": {
        "ref": "home",
        "map": {
          "value": {
            "path": "kitchen",
            "values": {
              "on": "On",
              "off": "Off"
            },
            "default": "Unavailable"
          }
        }
      }
    }
  ]
}
```

The secret is a long-lived access token from your Home Assistant profile → Security. Buttons call services on the same host: `/api/services/light/turn_off`.

## Example pages

These example pages show named sources at work. Replace the example hosts, VIN, Rachio IDs and Home Assistant entity IDs with your own before you use one:

| Page | Built from | Shows | Buttons |
| --- | --- | --- | --- |
| [GitHub starter](https://legatobar.com/examples/github-starter.json) | Public JSON API, no key | Repository stars and forks | none |
| [GitHub](https://legatobar.com/examples/github.json) | Classic token, GraphQL and REST, `fail` for GraphQL errors, one page for every repository (`owner`, `repo`) titled from the answer | Review requests, your pull requests, notifications, CI on each default branch, a year of contributions (`heatmap`), each repository's numbers and runs | Mark all read; Re-run failed jobs (`{answer.…}`, asks first) |
| [Calendar](https://legatobar.com/examples/calendar.json) | This Mac's calendars (`kind: calendar`), no key | The meeting under way or next, with a countdown; the month with a dot for each calendar's events, and the week ahead under it | Join (opens the meeting's link), New Event (opens a form to add one) |
| [Reminders](https://legatobar.com/examples/reminders.json) | This Mac's reminders (`kind: reminders`), no key | Due, Upcoming and No date to tick off, each list with its counts, what you've completed | Complete (checks the reminder off in Reminders) |
| [Reading](https://legatobar.com/examples/reading.json) | Three public feeds (`format: feed`), no key | Hacker News, Apple's developer news and the Swift blog, one tab each, every post a link | none |
| [Pi-hole](https://legatobar.com/examples/pihole.json) | Login sign-in shared by five linked pages, derived hourly history | Blocking status, the last 24 hours, each hour's traffic, top domains; Queries, Clients, Local DNS and Servers pages | Pause (a menu of lengths), Resume blocking |
| [AdGuard Home](https://legatobar.com/examples/adguard-home.json) | Basic sign-in shared by five linked pages, name-keyed lists as rows (`entries`), names from another request (`lookup`) | Protection, queries per hour, the last 24 hours, top domains; Queries, Clients, Blocklists and Local DNS pages | Pause (a menu of lengths), Resume, Safe Browsing and parental switches, Clear DNS cache, Update the lists |
| Home lab | Basic sign-in, Prometheus metrics, derived values | Overall health, services, jobs and backups, DNS, slowest responses, certificates | none |
| [Tesla](https://legatobar.com/examples/tesla.json) | Bearer token (Tessie), one request | Doors, battery, range, charging, temperatures, tire pressures | Lock, Start climate, Stop climate |
| [Sprinklers](https://legatobar.com/examples/rachio.json) | Bearer API key (Rachio), one request, derived counts | Controller status, rain sensor, enabled zones | Water a zone for 10 minutes, Stop watering |
| [Lunch Money](https://legatobar.com/examples/lunch-money.json) | Bearer token, sums over a list of accounts | Bank connections, cash, credit cards, balances by type | Sync banks |
| [Budget](https://legatobar.com/examples/ynab.json) | Bearer token (YNAB), the current month | Ready to assign, overspent categories, what's left in the biggest categories | none |
| [Todoist](https://legatobar.com/examples/todoist.json) | Bearer token, filter requests joined in order, parent and section names from other requests (`lookup`), one page for every project (`params`), a sort by two paths, a note when an answer is cut short | Due, Upcoming and the Inbox to tick off; open tasks per project; completions each day | Complete a task from its row |
| [Parcel](https://legatobar.com/examples/parcel.json) | `api-key` header, two requests shared by both pages, a sort by a derived rank then a date, one page for every package (`params`) found across both lists | What needs attention first, then what's on the way by expected day; recent deliveries; each package's tracking history | none |
| [Plex](https://legatobar.com/examples/plex.json) | `X-Plex-Token` header | Now playing with posters, Recently added, libraries with counts, whether the server answers | Stop on each stream (Plex Pass) |
| [Sonarr](https://legatobar.com/examples/sonarr.json) | `X-Api-Key` header, a sort by a derived rank, a size Sonarr doesn't know yet left out | Sonarr's own health checks, the download queue with posters, the week's episodes, recently missing episodes, library counts | Remove on each download, Search on each missing episode |
| [Radarr](https://legatobar.com/examples/radarr.json) | `X-Api-Key` header, three release dates joined into one agenda | The same as Sonarr, for films, with a month of cinema, digital and disc releases | Remove on each download, Search on each missing film |
| [Portainer](https://legatobar.com/examples/portainer.json) | `X-API-Key` header, Docker through Portainer's proxy, a sort by four filtered lists, a Keep running list (optional; without it every container has Stop), one page for every container (`params`) with History samples | Every container's state, what needs you, the running count, host facts; each container's CPU, memory and health checks | Start and Restart on each row; Start, Stop and Restart on a container's page |
| Home | Bearer token, one Home Assistant template | Alarm, water main, thermostat, doors and windows, safety sensors, lights | Room lights and scenes, shades, Apple TV, All lights off |

## Services you may already use

These consumer APIs were checked against their documentation on 2026-10-20. Each takes a token Legato can send and answers in JSON, so a page can read it without a script. The example pages above use them.

| Service | Signing in | Where to get the token | API docs |
| --- | --- | --- | --- |
| Tessie (for a Tesla) | `bearer` | Tessie settings → API | [developer.tessie.com](https://developer.tessie.com/reference/authentication) |
| Rachio | `bearer` | Rachio app → Profile → API key | [rachio.readme.io](https://rachio.readme.io/reference/authentication) |
| Lunch Money | `bearer` | my.lunchmoney.app/developers | [lunchmoney.dev/v2](https://lunchmoney.dev/v2/overview) |
| YNAB | `bearer` | Account settings → Developer settings → personal access token | [api.ynab.com](https://api.ynab.com/) |
| Todoist | `bearer` | Settings → Integrations → Developer → API token | [developer.todoist.com/api/v1](https://developer.todoist.com/api/v1/) |
| Parcel (Premium) | `{ "type": "header", "name": "api-key" }` | web.parcelapp.net → API key | [parcelapp.net/help](https://parcelapp.net/help/api-view-deliveries.html) |
| Jellyfin, Emby | `{ "type": "header", "name": "Authorization", "value": "MediaBrowser Token=\"{secret}\"" }` | Dashboard → API Keys (Emby: Settings → Advanced → API Keys) | [api.jellyfin.org](https://api.jellyfin.org) |
| Open-Meteo | None (free for non-commercial use) | Nothing to get | [open-meteo.com/en/docs](https://open-meteo.com/en/docs) |
| OpenWeather (One Call 3.0) | `{ "type": "query", "name": "appid" }` | openweathermap.org → My API keys, with **One Call by Call** subscribed | [openweathermap.org/api/one-call-3](https://openweathermap.org/api/one-call-3) |
| Plex Media Server | `{ "type": "header", "name": "X-Plex-Token" }` | Plex's [authentication token guide](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/) | [developer.plex.tv/pms](https://developer.plex.tv/pms/) |

Notes for each:

- **Tessie.** Replace each `YOUR_VIN` with your car's VIN. A command such as `/command/lock` answers `{ "result": true }`, which the page's `success` condition checks; the car may need to wake first.
- **Rachio.** IDs can't come from an earlier answer, so look yours up once: `GET https://api.rach.io/1/public/person/info` gives your person ID, and `GET /1/public/person/{id}` lists your devices and zones. Put them in place of `YOUR_DEVICE_ID` and `YOUR_ZONE_ID`. Rachio allows 3,500 requests a day.
- **Lunch Money.** Account balances need no dates. A monthly budget or spending summary does: `/v2/summary` requires a start and end date, which [`{date.month_start}` and `{date.month_end}`](https://legatobar.com/docs/source-requests.md#dates-in-requests) fill in. `balance` is a string; add up `to_base`, which is a number. **Sync banks** can run once a minute.
- **YNAB.** `last-used` stands for your most recent plan, and `months/current` for this month. Amounts are in milliunits; the example uses the `_currency` and `_formatted` fields YNAB adds beside them. YNAB allows 200 requests an hour per token.
- **Todoist.** Two pages, set up on [Todoist's own page](https://legatobar.com/services/todoist): download [todoist.json](https://legatobar.com/examples/todoist.json) and [todoist-project.json](https://legatobar.com/examples/todoist-project.json), and keep their IDs, since each project on the overview opens `todoist-project?project=<id>`, one page for every project. Today, overdue, upcoming (`7 days & !today & !overdue`) and the Inbox are each their own filter; Due joins today's and the overdue ones in that order, so old overdue tasks never jump ahead. A task's parent comes from every open task by `lookup`, for a subtask's `↳ Parent` line. A project's tasks come in no order, so the page sorts them by `["section.order_key", "order_key"]`, as Todoist shows them. Filters and lists are paged and Legato doesn't follow `next_cursor`, so the page checks for one: when an answer has more, a note links to Todoist and project counts say "At least". On the free plan the activity log behind **Recently completed** keeps only a short history.
- **Parcel.** Set up on [Parcel's own page](https://legatobar.com/services/parcel): download [parcel.json](https://legatobar.com/examples/parcel.json) and [parcel-package.json](https://legatobar.com/examples/parcel-package.json), and keep the ID `parcel-package`, since each row opens `parcel-package?n=<tracking number>&brand=<logo>`. Parcel has no request for one package, so that page reads the same two lists as the overview and keeps the one whose `tracking_number` matches. An answer can be a 200 with `"success": false`, so the pages check `success` before calling the list empty. Parcel answers from its own cache and allows 20 requests an hour; every 30 minutes is plenty. Packages also keeps each delivery in [History](https://legatobar.com/docs/history.md) as `parcel-deliveries`, for the Delivery times pages to read.
- **Plex.** Plex answers in XML unless asked for JSON. Legato sends `Accept: application/json` already, so don't override it. Use the server's local address over plain HTTP (`http://<server>:32400`) with **Secure connections** set to Preferred; an `https://` address by IP fails certificate checks. Use a token that doesn't expire: Plex's newer JWT tokens last 7 days and need a refresh Legato can't do. Don't trade a classic token for a JWT one: Plex retires the classic token when you do. The [Plex page](https://legatobar.com/services/plex) has the details.
- **Sonarr and Radarr.** Both answer on `/api/v3` with the key from **Settings → General** in an `X-Api-Key` header. Behind a reverse proxy at a path, keep the path out of `url` and put it in `base` (`"base": "/sonarr"`), so request, button and poster paths all get it. The [Sonarr](https://legatobar.com/services/sonarr) and [Radarr](https://legatobar.com/services/radarr) pages have the details.
- **Portainer.** Portainer CE reaches Docker for you: `/api/endpoints/<id>/docker/…` is Docker's own API. CE has no read-only role, so any token can stop containers, and no check for newer images. The [Portainer page](https://legatobar.com/services/portainer) has the details.

These didn't fit, so use a script or agent that [writes the page](https://legatobar.com/docs/page-writing.md#writing-a-page) with the data it fetched:

- **Oura.** Personal access tokens were retired in December 2025. The API now needs OAuth, with tokens that expire.
- **Philips Hue.** The bridge's v2 API needs HTTPS with the bridge's own certificate, which macOS doesn't trust. The v1 API puts the key in the URL path, and the remote API needs OAuth.



---

# Calendar and Reminders

## Calendar sources

A source with `"kind": "calendar"` reads every calendar on this Mac, the ones in Calendar's sidebar whether they're ticked or not, through macOS itself. Nothing is fetched from the internet and nothing leaves the Mac. It suits a page an agent writes for you, such as "my next meeting, with a Join button", next to everything else in the panel. [Examples/pages/calendar.json](https://legatobar.com/examples/calendar.json) is a complete page:

```json
"sources": { "calendar": { "kind": "calendar", "window": "month", "every": "5m" } },
"cards": [
  { "id": "up", "type": "countdown", "label": "Next up", "at": "2026-01-01T00:00:00Z",
    "source": { "ref": "calendar",
      "map": { "label": "up.title", "at": "up.at", "detail": "up.detail" },
      "empty": { "when": { "path": "has_up", "equals": false }, "text": "No timed events coming up" } },
    "actions": [ { "kind": "open", "label": "Join", "icon": "video.fill", "url": "{up.join}", "prominent": true,
                   "when": { "path": "up.has_join", "equals": true } } ] },
  { "id": "month", "type": "month", "days": 7, "hide_empty_days": true, "max_events": 7, "items": [],
    "source": { "ref": "calendar",
      "map": { "items": { "each": "agenda", "limit": 300, "fields": {
        "title": "title",
        "start": { "if": { "path": "all_day", "equals": true }, "then": "start_date", "else": "start" },
        "end": { "if": { "path": "all_day", "equals": true }, "then": "end_date", "else": "end" },
        "detail": "location", "url": "join", "color": "color" } } } },
    "actions": [ { "kind": "add-event", "label": "New Event", "icon": "calendar.badge.plus" } ],
    "actions_placement": "corner" }
]
```

The `month` card is a [`month`](https://legatobar.com/docs/card-time.md#month): this month as a grid, a dot in each calendar's colour on the days with events, and under it the chosen day (today until you click another) and the six after it, leaving out empty days, seven events at a time. `days` goes up to 30, to list the month ahead. `agenda` lists events in order and `limit` keeps the first so many, so size `limit` for your calendar: about 72 days are read, and a busy calendar may need up to the card's 300. The arrows beside the month's name page to other months, up to 12 either way: the source then reads that month too, so the card has its events.

Only `agenda` and `agenda_count` follow the month on screen; `up`, `next`, `today` and `events` stay with now, so a **Next up** card on the same source doesn't move.

Each row has a line at now, a **Join** button on the meeting under way, and its calendar's colour, as Calendar shows it. Change a calendar's colour in Calendar and the card follows. All-day events pass their dates (`start_date`, `end_date`) rather than moments, so they stay on their day.

For a list of the days ahead instead, use an [`agenda`](https://legatobar.com/docs/card-time.md#agenda) with `days` (up to 7) and a `window` that covers them: `"window": "3d"` with `"days": 3`, mapping `items` from `agenda` the same way.

| Field | Required? | Meaning |
| --- | --- | --- |
| `kind` | yes | `calendar`. |
| `window` | no | How far ahead to look, in hours or days from `1h` to `7d`, or `month` for a month card: the six weeks it shows, and the 30 days after them for its list (`days`). Default `2d`. |
| `calendars` | no | Calendar names to include, as Calendar shows them. Default: every calendar. |
| `every` | no | A safety refresh, default `5m`. The source also refreshes within seconds of a change in any calendar, when an event starts or ends, at midnight and when the time zone changes. |
| `derive` | no | As for any source. |

The answer, which `map` reads:

| Path | What it is |
| --- | --- |
| `up` | What the panel should show now: the event under way, else the next one. `title`, `at` (its end while under way, else its start, for a `countdown`), `detail` (how long, or "Now · until 10:45 AM", and where), `join`, `has_join`, `in_progress`, `calendar`. Null when nothing is coming. |
| `has_up` | Whether there is an `up`. |
| `next`, `current` | The next event to start, and the one under way, or null. |
| `today` | Every event today, including those already over (`past: true`). |
| `events` | What's under way or still to come within `window`. |
| `agenda` | Every event on every whole day `window` touches, including those already over: for an `agenda` or `month` card. With `"window": "2d"` at 10 AM, that's all of today, tomorrow and the day after. With `"window": "month"`, the grid's six weeks and the 30 days after them, so a month card's `days` list has its events; `events` still stops at the grid. |
| `today_count`, `agenda_count`, `busy_minutes_today`, `busy_today` | How many events today and in `agenda`, and the time booked today, with overlaps counted once (`busy_today` is formatted, such as "2h 45m"). |
| `empty` | "Nothing in the next 2 days", worded for `window` ("Nothing this month" for `month`). |

Each event has `title`, `start` and `end` (ISO 8601 with this Mac's offset), `all_day`, `time` ("9:30 AM" or "All day"), `time_range`, `day` ("Today", "Tomorrow", "Fri, Oct 30"), `location`, `join`, `has_join`, `calendar`, `color` (`#RRGGBB`), `in_progress` and `past`. All-day events also carry `start_date` and `end_date` (the last day, inclusive), since they belong to a date wherever the Mac is. Declined and cancelled events are left out. Times and day names follow this Mac's time zone and language.

`join` is a video-call link found in the event's URL, then its location, then its notes: Zoom, Google Meet, Microsoft Teams, Webex, FaceTime, Whereby, Chime, GoTo, Slack huddles and Discord. A link counts only when its host is the service's own (so `evilzoom.us` doesn't) and its path is a meeting's, and only over https. Links wrapped by Outlook SafeLinks or Google are unwrapped first.

**Add Event.** A button with `"kind": "add-event"`, on a card whose source is a calendar source, opens a **New Event** form in the panel, starting now. On a [`month`](https://legatobar.com/docs/card-time.md#month) card with another day chosen, it starts on that day instead, at the same time.

The button can fill it in: a `title` of 1–80 characters (a template filled from the answer, or plain text; default blank, and the form won't add the event until it has one), a `duration` from `5m` to `12h` (default `1h`), and a `calendar` by name (default: the calendar Calendar adds new events to).

The form also takes a location, all-day, the start and end, repeat (every day, weekday, week, two weeks, month or year), the calendar, an alert, a URL (`https://` is added when it's typed without one) and notes; **Add** (or Return) saves it and the card shows it at once. Unlike other buttons, it stays on a card that has nothing to show, since a free day is when it's wanted.

Run from Shortcuts, the button adds the event as its settings say, with no form (titled "New Event" when it sets no title); chosen in Spotlight, it opens the form on its page.

**Calendar access.** The first time a calendar source runs, its first card says what it would show and offers **Allow Calendar Access**, which brings up macOS's prompt; Legato never asks at launch. If access was turned off, the card offers **Open Privacy Settings** instead. If Legato may only add events, the card offers **Allow Full Access**; if an organization manages access, the card says so. Other cards on the same source wait for the first.

## Reminders sources

A source with `"kind": "reminders"` reads this Mac's reminders, the ones Reminders shows, through macOS itself, and a checklist row can check one off. Nothing leaves the Mac. The smallest page is a count and a checklist:

```json
"sources": { "reminders": { "kind": "reminders", "show": "overdue+today" } },
"cards": [
  { "id": "due", "type": "stat", "label": "Due today", "value": 0,
    "source": { "ref": "reminders", "map": { "value": "today_count",
      "delta": { "if": { "path": "overdue_count", "gt": 0 }, "then": { "template": "{overdue_count} overdue" }, "else": { "template": "None overdue" } } } } },
  { "id": "todo", "type": "checklist", "label": "Today and overdue", "mark": "fill", "items": [],
    "source": { "ref": "reminders",
      "map": { "items": { "each": "items", "limit": 20, "fields": { "text": "title", "detail": "detail", "done": "done" } } },
      "empty": { "when": { "path": "count", "equals": 0 }, "text": "{empty}" } },
    "itemAction": { "kind": "complete-reminder", "label": "Complete", "icon": "checkmark" } }
]
```

| Field | Required? | Meaning |
| --- | --- | --- |
| `kind` | yes | `reminders`. |
| `show` | no | `overdue`, `today` or `overdue+today` (the default), in `items`. `dashboard` and `all` answer differently (below). A reminder due on a date is overdue from the next day; one due at a time, from that time, as in Reminders. |
| `lists` | no | Reminders list names to include, as Reminders shows them. Default: every list. |
| `list_ids` | no | Lists to include by id, a `lists` row's `id`, with `show` `dashboard` or `all`. A list's page takes it from its link: `"list_ids": ["{param.list}"]`. Not with `lists`. |
| `days` | no | With `dashboard`: how many days after today `upcoming` reaches, 1 to 31. Default 7. |
| `completed_days` | no | With `dashboard`: how many days `completed` and `by_day` cover, today included, 1 to 31. Default 7. |
| `every` | no | A safety refresh, default `5m`. The source also refreshes within seconds of a change in Reminders, when a timed reminder falls due, at midnight and when the time zone changes. |
| `derive` | no | As for any source. |

The answer has `items`, oldest first (on one day, reminders without a time before timed ones), and `count`, `overdue_count`, `today_count` and `empty` ("All caught up").

Each item has `id`, `title`, `line` (the title, with when it's due after it when that says something: "Call vet · 9:30 AM", "Pay rent · Yesterday", and just "Water plants" for one due today with no time), `due` (ISO 8601, or null for a reminder due on a date), `due_date`, `all_day`, `time` ("9:30 AM", or empty), `when` ("Today 9:30 AM", "Mon, Oct 26"), `due_text` (what `line` adds), `list`, `color` (the list's, `#RRGGBB`), `overdue`, `today`, `priority` (`high`, `medium`, `low` or `none`), `repeat` (how often it repeats: "Daily", "Weekly", "Monthly", "Yearly" or "Every 10 days", "Every 3 weeks"; a rule on set weekdays still reads "Weekly"; empty when it doesn't repeat), `detail` (the line Reminders shows under a title: `due_text`, `list` and `repeat`, those that say something, joined with " · ", such as "9:30 AM · Home · Weekly"; map it to a checklist item's `detail`), `notes`, `url` and `done` (always false, for a checklist's `done`).

With the first three shows, only incomplete reminders with a due date are read.

**A whole overview: `show: "dashboard"`.** One read of every open reminder and those completed lately, for the [Reminders](https://legatobar.com/services/reminders) pages:

- `due`: today's reminders (without a time first, then by time, including those whose time has passed), then earlier overdue days, newest first. Each reminder once. `due_count`, `today_count`, `overdue_count`.
- `upcoming`: due in the `days` after today, by day. `upcoming_count`.
- `undated`: no due date, the oldest made first. `undated_count`.
- `lists`: every list, the most open reminders first, each with `id`, `title`, `color`, `open`, `overdue` (those due before today, the ones under Overdue) and `detail` ("8 open · 2 overdue", "None open"). `list_count`.
- `completed`: completed in the last `completed_days`, newest first, each with `id`, `title`, `list`, `list_id`, `color` and `completed` (ISO 8601, for `|ago`). `done_count`, `done_today`, and `by_day`: one `{label, date, count}` per day, oldest first, for a `columns` card.

**One list: `show: "all"`.** Every open reminder in `items`, overdue (oldest first), today, later, then undated, with `count`, `list_title` (for the page's `title_from`) and `empty`, which says so when the list is gone.

Rows from these two shows add `list_id`, `group` (the heading they go under: Today, Overdue, Tomorrow, "Thu, Nov 19", Upcoming or No date; map it to a checklist's `section`), `day` ("Today", "Mon, Oct 26", empty with no date), `info` (day, time and list: "Today · 9:30 AM · Home"), `info_short` (without the list), `repeats` (true or false, for a repeat badge) and `priority_mark` (`!!!`, `!!`, `!` or empty, as Reminders puts before a title). An undated row has a null `due` and `due_date`.

Ticking a repeating reminder does what Reminders does: the occurrence is kept as completed and the reminder moves to its next date, with the same `id`. Ticking from one card reads every reminders source again, so another page showing the same reminder catches up at once.

Sections, tags, flags, subtasks and a list's own order aren't available to apps, so a page can't show or filter by them. A subtask is an ordinary reminder in its list.

A checklist on a reminders source can carry `"itemAction": { "kind": "complete-reminder", "label": "Complete" }`: ticking a row marks it done at once (with `"mark": "fill"`, its circle fills, as in Reminders), and after a moment marks that reminder done in Reminders and fades the row out. Ticking it again during that moment undoes it, and nothing changes in Reminders. (Every checklist row action waits the same way.) It finds the reminder by the row's `id`. `complete-reminder` works only as a checklist's `itemAction` on a reminders source, not as a button.

**Reminders access.** It's a separate permission from Calendar. The first read's card offers **Allow Reminders Access**, which brings up macOS's prompt; if access was turned off, **Open Privacy Settings**.



---

# Buttons

<a id="buttons"></a>

Add `actions` to a card that has a source, and it gets buttons: pause ad blocking, turn on a light, start a sprinkler zone. Each button sends a request to the same service as the source, signed in the same way, and Legato then refreshes the source to check for the change.

Where a button goes on a card and the fields it takes are below. Buttons that do more have a page each:

- [Tasks and asking first](https://legatobar.com/docs/button-tasks.md): Buttons that follow a long-running task, ask before they run, or name what the card is showing.
- [Text input](https://legatobar.com/docs/button-input.md): Buttons that open a form for typed text or a pick from a list.
- [Rows and checklists](https://legatobar.com/docs/button-rows.md): An action for each checklist row, and buttons at the end of each row of a list.

A card can also be only its buttons: a [`text`](https://legatobar.com/docs/card-text.md#text) card with a `label`, no `body`, and a `source` with just its `ref`, no `map`. The buttons' `when` conditions still read that source's answer. A machine's Controls card is one:

```json
{ "id": "controls", "type": "text", "label": "Controls", "actions_placement": "corner",
  "source": { "ref": "guest" },
  "actions": [{ "label": "Start", "icon": "play.fill", "path": "/api2/json/nodes/pve/qemu/107/status/start",
                "when": { "path": "status.data.status", "equals": "stopped" } }] }
```

Every button also shows up in Spotlight under its own label: choose it and press Return, and Legato presses it, then opens its page (Settings → General → "Open the page when you press a button from Spotlight" turns that off). This `actions` field is a card fragment for the Pi-hole source:

A button that changes many things at once, such as one that accepts every suggestion on a list, can stay in the panel with `"offer": false`: Spotlight, Shortcuts and notifications then never offer it, so it's only pressed where the panel shows what it acts on. Give it `"confirm"` too, so the panel asks before it runs: `offer` alone doesn't ask.

A button in a card's corner is its icon alone, its name in a tooltip. When the icon wouldn't say enough, for a change that reaches every device, `"show_label": true` draws its name beside its icon in a plain bordered button: Pi-hole's Queries page has **Block domain**, **Allow domain** and **Remove from deny list**, each shown only for the query it fits.

### Put each button on the card it changes

A card's buttons are drawn inside it, under what it shows. So attach each button to the card whose value it changes, not to a card of its own: Start climate on the cabin temperature, Lock on the doors' status, Water now on the zone it waters. The card then reads as one control: what's true now, and what you can do about it. The Tesla example's Inside card does this:

```json
{
  "id": "inside", "type": "stat", "label": "Inside", "unit": "°F",
  "source": { "ref": "tesla", "map": {
    "value": { "path": "climate_state.inside_temp", "scale": 1.8, "offset": 32, "round": 0 },
    "delta": { "path": "climate_state.is_climate_on", "values": { "true": "Climate on", "false": "Climate off" } } } },
  "actions": [
    { "label": "Start climate", "icon": "fan", "method": "POST", "path": "/YOUR_VIN/command/start_climate",
      "when": { "path": "climate_state.is_climate_on", "equals": false } },
    { "label": "Stop climate", "icon": "fan.slash", "method": "POST", "path": "/YOUR_VIN/command/stop_climate",
      "when": { "path": "climate_state.is_climate_on", "equals": true } }
  ]
}
```

(The full example adds `success` and `error`; see the table below.)

- **Show the state the button changes on the same card.** Here `delta` says "Climate off", so after a press the follow-up read turns it to "Climate on" right above the button, and the person sees it worked.
- **Offer only the button that makes sense now.** Give opposite actions opposite `when` conditions, as Start and Stop climate do, so one button shows at a time, in the same place. Mark the one that ends something running `"prominent": true`, as the Tesla example does for Stop climate: the filled button says "this is on" at a glance.
- **Label with a verb, briefly.** "Start climate", "Lock", "Pause 5m": up to 24 characters, with an SF Symbol `icon` that matches.
- **Keep it to one or two per card.** Up to four fit; they sit side by side and stack when the card is too narrow, as a half-width card often is.
- **Or put them in the card's corner.** `"actions_placement": "corner"` on the card puts its buttons at its top right, beside what it shows, instead of in a row under it. Each is drawn as its icon alone, with its label as the tooltip, so the card's own lines keep their room; give each button an `icon` (one without keeps its label). A button with `"confirm": true` asks in the corner too ("Reboot?", then ✕ and ✓), and the corner keeps room for that question all along, so asking doesn't move the card's lines. A question with its own `message`, or a name to type, needs the card's width and asks under the card. The corner suits a short card with a few buttons, such as Start or Stop climate on the cabin temperature, or a server's Start, Shut down and Reboot. On a text card that's only its name and buttons (no `body`), the corner buttons are drawn at the size of buttons under a card, beside the name. On a list, and on a facts or text card with a `label`, they sit on the name's line and the rows below keep the card's full width. A card with no name has no such line, so they sit beside its lines, which take the rest of the width: give a facts card a `label` to keep its values at the right edge. `"bottom"`, under the card, is the default.

- **Or put them in the page's title row.** `"placement": "title"` on a text card of buttons (no `body`) draws them at the right of the page's large title, as a window's toolbar: each its icon alone, its label in a tooltip, a menu showing its value. An on/off pair that shares a `setting`, each half with `turns`, is one icon, lit on a grey plate while it's on. Several such cards sit in one row, a thin line between them. The person arranges the row in Customize Controls (right-click the row, or the end of ⋯): one shelf of what's in the bar, in order, and one of the rest, with controls dragged along or between them. ⋯ always shows, and opens the rest as working rows (switches switch, menus show their value), each with ＋ to put it in the bar. Menus in the row show their icon and value with no pill. Only a sheet page in the window has the large title; elsewhere the card is drawn as an ordinary card. Spotlight and Shortcuts offer every one either way.

- **Or make them settings rows.** `"actions_placement": "rows"` draws each button with a `setting` as a row named by it, the way System Settings lists them: a menu (`choices`) shows its value on the row's right, and an on/off pair of buttons sharing one `setting`, each with `"turns": "on"` or `"off"`, is a switch. Give the pair `when`s that never hold together: the one shown says the state, so the switch is on while the button that turns it off is the one offered, and flipping it presses that button, question and all. Buttons with no `setting`, such as Start charging, sit in the card's corner. Rows suit a Controls card on a [sheet](https://legatobar.com/docs/page-writing.md), where they read like the facts beside them. Up to 16 buttons.

```json
{ "id": "controls", "type": "text", "label": "Controls", "actions_placement": "rows", "source": { "ref": "car" },
  "actions": [
    { "label": "Turn on Sentry", "icon": "eye", "path": "/sentry/on", "setting": "Sentry", "turns": "on", "when": { "path": "sentry_mode", "equals": false } },
    { "label": "Turn off Sentry", "icon": "eye.slash", "path": "/sentry/off", "setting": "Sentry", "turns": "off", "when": { "path": "sentry_mode", "equals": true } } ] }
```
- **Or offer a menu of values.** Give a button `choices`, each a `label` and a `value`, and put `{choice}` in its `path`, `body` or `headers`: the button becomes a menu, and picking one sends the request with that value, such as a cabin temperature or a charge limit. `current` names where the source's answer holds the value now; that choice is ticked and titles the menu (70°F ▾). When the answer holds a value no choice has, such as the highest setting while a car defrosts, the menu shows the button's `icon` instead (its label without one). The labels can say one thing and the values another, such as °F labels for a service that takes °C:

```json
{ "label": "Cabin temperature", "path": "/car/command/set_temperatures?temperature={choice}",
  "current": "climate_state.driver_temp_setting",
  "choices": [{ "label": "68°F", "value": 20 }, { "label": "70°F", "value": 21 }, { "label": "72°F", "value": 22 }] }
```

  In a `body`, a string that is `"{choice}"` and nothing else takes the choice's value as it is, so a number stays a number. AdGuard Home's pause wants milliseconds as a number and refuses `"300000"`:

```json
{ "label": "Pause protection", "icon": "pause", "path": "/control/protection",
  "body": { "enabled": false, "duration": "{choice}" },
  "choices": [{ "label": "1 minute", "value": 60000 }, { "label": "1 hour", "value": 3600000 }] }
```

  Any other body string, such as `"for {choice} ms"`, is filled as text, where a number is grouped (`300,000`); `{choice|raw}` gives the digits as sent.

  Spotlight and Shortcuts list each choice as its own button, "Cabin temperature: 70°F". A menu can't ask first (`confirm`).
- **Or make the menu from the answer.** When the choices are things the service lists, such as the models an Ollama server has installed, `choices` can be a list rule instead: `each` names the array, and `fields` gives each choice's `label` and `value`. Picking one sends the request with that value, as a fixed menu does:

  ```json
  { "label": "Load a model", "icon": "play.fill", "path": "/api/generate",
    "body": { "model": "{choice}" },
    "choices": { "each": "tags.models", "fields": { "label": "name", "value": "name" } } }
  ```

  The menu is read from the source's answer each time it opens: up to 24 choices in the answer's order (a `where` or `sort` in the rule changes that), each label cut to 24 characters. A choice is pressed by its value, so if the list changes before you pick, the request still goes to the one you picked, or not at all if it's gone. With nothing to choose, or two choices with the same value, the button is dimmed and its tooltip says why. `current` ticks the choice the answer holds, as on a fixed menu. A menu made from the answer stays in the panel: Spotlight, Shortcuts and notifications don't offer it, since its choices change. It can't go on a row or a checklist's `itemAction`.
- **Or send a time.** Some services want a moment in the request, such as when a silence or a snooze ends. In a body, `{action.at}` is the moment of the press and `{choice|from_now}` is the moment a menu's number of seconds from then, both in ISO 8601 UTC (`2026-11-17T20:41:05Z`). Grafana's Silence menu sends both:

  ```json
  { "label": "Silence", "icon": "bell.slash", "path": "/api/alertmanager/grafana/api/v2/silences",
    "body": { "matchers": [{ "name": "__alert_rule_uid__", "value": "{param.uid}", "isEqual": true, "isRegex": false }],
              "startsAt": "{action.at}", "endsAt": "{choice|from_now}", "createdBy": "Legato", "comment": "Silenced from Legato" },
    "choices": [{ "label": "1 hour", "value": 3600 }, { "label": "1 day", "value": 86400 }, { "label": "1 week", "value": 604800 }] }
  ```

  `{action.at}` goes wherever `{action.id}` does, on a card's buttons and a row's. `from_now` reads any number of seconds, so `{answer.snooze|from_now}` works too.
- **Part them into runs.** Put `"|"` between two buttons in `actions` to start a new run of them: the panel draws a thin upright line between the runs that show, as in Lock, Sentry | climate, defrost, steering wheel heat | seats. A run whose buttons are all hidden leaves no line. A card holds up to six buttons, or sixteen in its corner (the `"|"` don't count), so one Controls card can carry a car's on/off pairs, one of each showing at a time.
- **Or centre the row.** `"actions_align": "center"` on the card centres the row of buttons under it; the card's label and lines stay where they are. It suits a card that is mostly its buttons, such as a row of scenes. `"leading"` is the default.

```json
"actions": [
  { "label": "Pause 5m", "icon": "pause.fill", "method": "POST", "path": "/api/dns/blocking",
    "body": { "blocking": false, "timer": 300 }, "when": { "path": "blocking.blocking", "equals": "enabled" } },
  { "label": "Resume", "icon": "play.fill", "method": "POST", "path": "/api/dns/blocking",
    "body": { "blocking": true, "timer": null }, "when": { "path": "blocking.blocking", "equals": "disabled" } }
]
```

| Field | | |
| --- | --- | --- |
| `kind` | optional | `http` (the default) calls the service, as below. `open` opens an address instead; see after this table. `add-event` opens a New Event form on a calendar source's card; see [Calendar sources](https://legatobar.com/docs/source-calendar.md#calendar-sources). `complete-reminder` works only as a checklist's `itemAction`; see [Reminders sources](https://legatobar.com/docs/source-calendar.md#reminders-sources). |
| `label` | required | 1–24 characters. It can show a value from the answer, `{answer.name}`; see [Buttons that act on what the card shows](https://legatobar.com/docs/button-tasks.md#buttons-that-act-on-what-the-card-shows). |
| `icon` | optional | An SF Symbol name. |
| `method` | optional | `POST` (the default), `PUT`, `PATCH`, `DELETE` or `GET`. Use `GET` only for a service that takes a command that way, such as changedetection.io's `?recheck=1`. A `GET` sends no `body` or `form`, so its values go in the path's query. |
| `path` | required | Starts with `/`, and is added to the source's scheme, host and port. It can't name another host. `{answer.<path>}` fills a value from the card's answer. |
| `body` | optional | A JSON body. Its strings can take `{answer.<path>}` too. |
| `graphql` | optional | A GraphQL request in place of `body`: `{ "query": "…", "variables": { … } }`. See [Buttons that send GraphQL](#buttons-that-send-graphql). |
| `form` | optional | A form in place of a JSON `body`, for services whose commands read only a form: `{ "hashes": "all" }`. See [Buttons that send a form](#buttons-that-send-a-form). |
| `headers` | optional | Extra headers for the button request, as `{ "name": "value" }`. Common source `headers` are inherited; button headers can override them. Keep credentials in a named secret. |
| `when` | optional | Show the button only when the source's last answer meets a [condition](https://legatobar.com/docs/mapping-conditions.md#conditions), such as `{ "path": "blocking.blocking", "equals": "enabled" }`. With it, a card can offer Pause while blocking is on and Resume while it's paused. |
| `success` | optional | A condition checked against the button's JSON response, such as `{ "path": "result", "equals": true }`. Use this when HTTP success alone does not mean the service accepted the command. |
| `error` | optional | A path to the failure reason in the button's response, such as `"reason"`. |
| `prominent` | optional | `true` draws the button filled in the accent colour. Use it for the one that matters most right now, such as Stop climate while the climate runs. Off by default. |
| `confirm` | optional | Ask in the panel before the request goes out: `true` asks the label with a question mark, or `{ "message", "button", "type" }` gives the question (up to 160 characters), the button that runs it (up to 24) and text to type first (up to 40), each optional; the question and the text to type can take `{answer.<path>}`. See [Buttons that ask first](https://legatobar.com/docs/button-tasks.md#buttons-that-ask-first). |
| `timeout` | optional | How long the request may take, in seconds: 60 (the default) to 1800. For a service that works only while the request stays open, such as Ollama, which stops downloading a model when the request closes. The button spins until the service answers. A button with more than 60 is pressed only in the panel: Spotlight, Shortcuts and notifications don't offer it. |
| `inputs` | optional | Ask for what to send: 1 to 4 fields, typed text or a pick from a list, filled into the request as `{input.<name>}`. A press opens a form in the page's place. See [Buttons that ask for text](https://legatobar.com/docs/button-input.md#buttons-that-ask-for-text). On an `open` button, the form opens one of your pages with what was typed, such as a search: see [Forms that open a page](https://legatobar.com/docs/button-input.md#forms-that-open-a-page). |
| `submit` | optional | With `inputs`: the form's own button, up to 24 characters. "Add" unless set. |
| `rule` | optional | Legato presses the button itself: `{ "when": …, "every": "6h" }`. See [Buttons that press themselves](#buttons-that-press-themselves). |
| `shown` | optional | `false`, with a `rule`: the button isn't drawn or offered anywhere, and only its rule presses it. |

- A card can have up to 6 buttons; give them `when` conditions so only the ones that fit the state show at once. They're hidden until the source has answered once, since what a button means can depend on the state.
- A button runs only when you click it, and only on this Mac. While it runs it shows a spinner; a press may take up to a minute, since a car has to wake up first, for example, or as long as its `timeout`. After an accepted command the source checks again at once, and again 2, 5, 20 and 60 seconds later.
- HTTP success means the request reached the service successfully. A configured `success` condition decides whether the response reports a successful command. Without that condition, `result: false` or `response.result: false` is treated as failure automatically; other HTTP 2xx responses are accepted. A failure reason appears under the card for two minutes.
- Command acceptance does not prove the device has changed state yet. The follow-up reads update the card with the service's latest state; those reads can themselves fail or report the old state.
- A button needs a source on the same card: it calls that source's service, signed in the same way. A card with written-in values can't carry one.

### Buttons that press themselves

A `rule` presses a button for you. Each time the card's source answers, Legato checks the rule's `when` against the answer, derived values included. When it holds, and the time in `every` has passed since the rule last pressed, the button is pressed the way a click presses it, with the same checks. A press that fails waits the same `every` before the next try. Rules run only while Legato is open and the Mac is awake.

This suits upkeep you'd otherwise have to remember, such as asking a bank to sync once its last full sync is 12 hours old:

```json
{ "label": "Sync banks", "method": "POST", "path": "/v2/plaid_accounts/fetch", "shown": false,
  "rule": { "when": { "path": "age", "gte": 12 }, "every": "6h" } }
```

`every` is at least `15m`. With `"shown": false`, only the rule presses the button: it isn't drawn on the card or offered to Spotlight, Shortcuts or notifications. Leave `shown` out to keep the button on the card as well. A rule can't go on a button that asks first (`confirm`), takes `inputs` or `choices`, or sits on a row. Details lists the page's rules under **Rules**, with when each last ran and whether the press went through.

### Buttons that send GraphQL

A service with a GraphQL API takes every change as a mutation sent to one address. Give the button `graphql` in place of `body`, and it sends `{ "query": …, "variables": … }` there. This button marks an issue done in an issue tracker:

```json
{ "label": "Done", "icon": "checkmark", "path": "/graphql",
  "graphql": {
    "query": "mutation($id: String!, $state: String!) { issueUpdate(id: $id, input: { stateId: $state }) { success } }",
    "variables": { "id": "{answer.issue.id}", "state": "{answer.done_state}" } },
  "success": { "path": "data.issueUpdate.success", "equals": true } }
```

- `query` goes exactly as written. Its braces belong to GraphQL, so Legato never fills anything in it. Put each value in `variables` and use it in the query as `$name`. A query holding `{answer.…}`, `{input.…}`, `{action.id}` or `{param.…}` won't load, since it would go out unfilled; nor will `{choice}` in a menu's query.
- `variables` is filled like a `body` in that kind of button: `{answer.…}` on a card's button, `{choice}` on a menu, `{input.…}` from a form, a row's own fields on a row's button or a checklist's `itemAction`. A string that is one placeholder alone keeps its type, so a number stays a number for an `Int!`. Leave `variables` out for a mutation that takes none.
- The request is always a `POST` to `path`. A button can't have `graphql` and `body` together, and it can't follow a task with `completion`.
- A GraphQL service usually answers HTTP 200 even when it refuses, so any `errors` in the answer fails the press, with the first one's message as the reason, even when `data` came back as well, since part of the mutation may not have run. An answer with no `data` fails too. Legato doesn't send the press again, with one exception: on a source that signs in for a session, a press refused with HTTP 401 goes once more after signing in again, since the service ran nothing. `success` then checks `data` the way it checks any answer.
- A query the service can't read often gets HTTP 400 with `errors`; the first message is the reason shown.

### Buttons that send a form

Some services read a command's values only from a web form (`application/x-www-form-urlencoded`), not from JSON. qBittorrent is one. Give the button `form` in place of `body`, and it sends each field as `name=value`. This row button stops a torrent in qBittorrent:

```json
{ "label": "Stop", "icon": "stop.fill", "path": "/api/v2/torrents/stop",
  "form": { "hashes": "{hash}" } }
```

- `form` is an object of 1 to 20 fields. Each value is text, a number or `true`/`false`, and is filled like a `body` in that kind of button: `{answer.…}` on a card's button, `{choice}` on a menu, `{input.…}` from a form, a row's own fields on a row's button or a checklist's `itemAction`.
- Each value goes as text: a number as its digits (`1048576`, never `1,048,576`), `true` and `false` as words. A value filled with a list or an object can't be sent, and the press fails.
- An empty optional `{input.…}` leaves its field out, as in a JSON body. A field written as `""` goes as `name=`.
- The fields go in name order, and the request's `Content-Type` is always the form's: a `Content-Type` in the source's or the button's `headers` doesn't change it.
- A form request never follows a redirect.
- The method is `POST` (the default), `PUT` or `PATCH`. A button can't have `form` with `body` or `graphql`.



---

# Tasks and asking first

### Buttons that follow a task

Some services answer a command with a task to follow: Proxmox starts a backup or a shutdown and returns the task's id. Give that button `completion`, and Legato follows the task until it ends:

```json
"completion": {
  "path": "/api2/json/nodes/pve/tasks/{data}/status",
  "done": { "path": "data.status", "equals": "stopped" },
  "success": { "path": "data.exitstatus", "equals": "OK" },
  "interval": 2,
  "timeout": 300
}
```

| Field | Required? | Meaning |
| --- | --- | --- |
| `path` | yes | The task's address on the source's host, filled from the command's answer. Filled values are escaped, so an id with `:` or `/` in it stays one part of the path. |
| `done` | yes | A condition on the task's answer that holds once it has ended. |
| `success` | yes | A condition that must also hold then, or the press didn't work. |
| `interval` | no | Seconds between reads of the task, 1 to 60. Default 2. |
| `timeout` | no | Seconds to follow it, 1 to 3600. Default 300; a backup can need 3600. |

- **While it runs:** Legato reads the task with GET, signed in as the source is, and the button shows as busy. A press from Shortcuts or Spotlight returns once the service accepts the command; Shortcuts says it started, and the panel shows how it ends.
- **When it doesn't end well:** the card says so if the task fails, its status can't be read, or the timeout passes first. The card is read again either way, since the command went through. Check the service before pressing again: Legato losing track of a task doesn't stop it.
- **Quitting Legato** stops following the task, and it isn't picked up again on the next launch.
- **A button with `when`** reads its source once more just before sending, so a Start chosen from an old answer isn't sent to a guest that's already running. The service still decides; this isn't a lock.

`completion` doesn't change who asks first: the panel and Shortcuts ask when the button has `confirm`, and Spotlight presses it directly. A checklist row's action can't have it.

In an action body, `{action.id}` becomes a new UUID for each press. Transport retries keep that UUID. This is suitable for command deduplication; a timestamp is not. When a service wants the time of the press instead, `{action.at}` gives it in ISO 8601 UTC. A `success` condition still needs to check the service’s command result when HTTP 200 can contain a refusal.

### Buttons that ask first

Some presses are hard to undo: restarting a server, shutting down a machine other things run on. Give that button `confirm`, and a click in the panel shows a question in its card, where the buttons were, with Cancel and a button that runs it. Nothing is sent until that button is pressed.

```json
{ "label": "Restart host", "icon": "power", "path": "/api2/json/nodes/pve/status", "body": { "command": "reboot" },
  "confirm": { "message": "Restart pve? Every guest stops first.", "button": "Restart", "type": "pve" } }
```

- With `type`, the button stays dimmed until that text is typed exactly, as when a service asks for a name before deleting it. Keep it for the press that would cost the most.
- `"confirm": true` asks "Restart host?" with the label as the button.
- Escape cancels. Choosing another page or closing the panel puts the question away.
- **Spotlight presses it directly.** Choosing a button by name in Spotlight is the decision, so it doesn't ask again.
- **Shortcuts asks first,** with `message` when there is one (it doesn't ask for the typed text).
- **It never goes on a notification,** which can't ask, even with a `success` check.
- A checklist's `itemAction` can't ask first: a tick is meant to be quick. Put an action that needs a question on a button.

A button with `"kind": "open"` opens an https address from the source's answer in the browser, and sends nothing to the service. It takes `label`, `icon`, `url`, `when` and `prominent`. `url` is a template, such as `"{up.join}"` for a meeting's Join button or `"{html_url}"` for a GitHub page. An address that isn't https with a host doesn't open, and the card says why. As an `itemAction`, it fills `url` from the ticked row. With `inputs`, it's a form that opens one of your pages with what was typed, such as a search: see [Forms that open a page](https://legatobar.com/docs/button-input.md#forms-that-open-a-page).

For Home Assistant, this single action object goes inside a card's `actions` array:

```json
{ "label": "Turn off", "icon": "power", "method": "POST", "path": "/api/services/light/turn_off",
  "body": { "entity_id": "light.kitchen_main_lights" }, "when": { "path": "kitchen", "equals": "on" } }
```

### Buttons that act on what the card shows

Some requests name the thing the card is showing: the run that failed, the newest request waiting for approval, the stream playing now. Put `{answer.<path>}` in the button, and the press fills it from the card's source answer (after `derive`). This is a repository page's Re-run failed jobs, whose source derives `failed_run_id` and `failed_run_name` from the newest failed run:

```json
{ "label": "Re-run failed jobs", "icon": "arrow.clockwise", "method": "POST",
  "path": "/repos/example-org/example-app/actions/runs/{answer.failed_run_id}/rerun-failed-jobs",
  "confirm": { "message": "Re-run the failed jobs of {answer.failed_run_name}?", "button": "Re-run" },
  "when": { "path": "failed_run_id", "exists": true }, "error": "message" }
```

| Where | How the value goes in |
| --- | --- |
| `path` | As sent: a number as its digits (`18765432109`, never grouped), percent-encoded so `/`, `?`, `&` or `#` can't change the address. |
| `body` strings | A string that is `"{answer.x}"` and nothing else takes the value as the answer has it, so a number stays a number and a list stays a list. In other text, a number goes as its digits. |
| `label` | As the card writes text, cut to 24 characters. Keep words of its own, such as "Stop {answer.name}": Spotlight and Shortcuts list the button by them. |
| `confirm` `message` and `type` | As the card writes text; the question is cut to 160 characters. With `type`, the name to type can come from the answer, for a delete. |
| `completion` `path` | Filled at the press, as the path is; the task's own id still comes from the command's answer. |
| `headers` | Never: headers carry credentials. A page with one there doesn't load. |

- **The press uses the answer the card is showing.** Nothing is read again first, and nothing checks the service: if the run was re-run elsewhere, the service's refusal shows under the card, with its reason when `error` names where the answer gives one. Each value can be a filter's output, as in `{answer.name|lower}`.
- **A value the answer lacks** leaves the button dimmed, saying why when you point at it ("the answer has no failed_run_id"), and nothing is sent. So does one a path can't take: an empty text, `.` or `..`, a list, or a whole number too big to send exactly (give a big id as text in `derive`). `when` is how a page hides the button instead, as above. The Source Preview window lists such buttons under Issues.
- **If the card changes under you,** the press doesn't go out. A click, a menu choice or a form's Add sends only while the card's values are the ones it was chosen from; a question that's open goes away when they change, and the card says to press again.
- **Spotlight presses it with the latest answer,** without asking, as for any button. **Shortcuts** asks with the filled question and stops if the values change while it asks. A button whose values are missing is listed, but isn't pressed: both say it has nothing to act on.
- **It never goes on a notification,** which can stay for hours: a press from it would act on whatever the answer says then.
- A checklist's `itemAction` fills from its own row (`{id}`), not from `{answer.…}`. An `open` button's `url` and an Add Event `title` already read the answer with plain paths, such as `{html_url}`.

The same pattern fits other services. A series page's Search on Sonarr sends the series' number as a number:

```json
{ "label": "Search", "icon": "magnifyingglass", "path": "/api/v3/command",
  "body": { "name": "SeriesSearch", "seriesId": "{answer.series.id}" } }
```

Approving the oldest waiting request on Seerr names it first. Seerr's request list has no titles, so the page looks each one up with a [request for each row](https://legatobar.com/docs/source-requests.md#a-request-for-each-row) and derives `rows`, each with its `id` and `title`:

```json
{ "label": "Approve", "icon": "checkmark", "path": "/api/v1/request/{answer.rows[0].id}/approve",
  "confirm": { "message": "Approve {answer.rows[0].title}?" }, "when": { "path": "rows[0].title", "exists": true } }
```

And Tautulli ends the stream the card shows, with its session's key in the query: `"path": "/api/v2?cmd=terminate_session&session_key={answer.stream.session_key}"`.



---

# Text input

### Buttons that ask for text

Some requests need something only you know: a tracking number, a note, a name. Give that button `inputs`, up to 8. A press opens a form in the page's place, as Add Event's does (or [over the page](#a-form-over-the-page)), and the form's own button (`submit`, "Add" unless set) sends the request with what was typed. This is the Packages page's Add tracking, for Parcel's add-delivery request:

```json
{ "label": "Add tracking", "icon": "plus", "path": "/external/add-delivery/",
  "inputs": [
    { "name": "number", "label": "Tracking number", "required": true, "max": 40,
      "pattern": "[A-Z0-9]{8,40}", "spaces": "remove", "case": "upper",
      "hint": "As the carrier prints it", "invalid": "Letters and digits only" },
    { "name": "carrier", "label": "Carrier", "kind": "choice", "required": true,
      "choices": [{ "label": "USPS", "value": "usps", "icon": "si:usps" },
                  { "label": "UPS", "value": "ups", "icon": "si:ups" },
                  { "label": "FedEx", "value": "fedex", "icon": "si:fedex" }],
      "guess": { "from": "number", "rules": [{ "pattern": "1Z.*", "value": "ups" },
                                             { "pattern": "9[2-5][0-9]{20}", "value": "usps" }] } },
    { "name": "description", "label": "Description", "required": true, "max": 60, "placeholder": "What's in it" }
  ],
  "body": { "tracking_number": "{input.number}", "carrier_code": "{input.carrier}", "description": "{input.description}" },
  "success": { "path": "success", "equals": true }, "error": "error_message" }
```

| Input field | | |
| --- | --- | --- |
| `name` | required | A letter, then letters, digits or `_`. `{input.<name>}` fills it. |
| `label` | required | 1–24 characters, above the field. |
| `kind` | optional | `text` (the default), one line; `choice`, one of `choices`: chips when there are up to 6, a menu when there are more; or `toggle`, an on/off switch. |
| `on_value`, `off_value` | toggle | What a toggle sends when it's on and when it's off: a string, a number, true or false, or a list of up to 20 strings or numbers. Unless set, on is `true` and off is `false`; with an `on_value` and no `off_value`, the key is left out of the body when it's off. |
| `required` | optional | Add stays dimmed until every required field has something in it. |
| `placeholder`, `hint` | optional | Up to 40 characters. The hint is the line under the field, where a problem shows instead. |
| `max` | text | The longest value, 1–200 characters after `spaces` and `case`. 100 unless set. |
| `pattern` | text | A regular expression the whole value must match, such as `[A-Z0-9]{8,40}`. `invalid` (up to 80 characters) is what a value that misses it is told. |
| `spaces`, `case` | text | `"spaces": "remove"` takes every space out; `"case"` is `upper`, `lower` or `keep`. Both apply before the value is checked and sent, so a pasted `1z 999 aa1` goes out as `1Z999AA1`. |
| `default` | optional | A text input's starting text, or a choice's value. |
| `choices` | choice | 2–24 of `{ "label", "value", "icon" }`, the icon optional. |
| `guess` | choice | Picks a choice from a text input as it's typed: the first rule whose `pattern` matches all of it. A pick by hand stays. |
| `start` | optional | What the field opens on, read from the row (a row's button) or the card's answer, such as `"payee"`. See [Edit forms](#edit-forms). |
| `multiple` | choice | `true` takes several of the choices, as checkboxes, and sends them as a list. |
| `lines` | text | 2–8 lets the text run over lines, as notes do, growing to that many before it scrolls. |

- **Every field is checked before anything is sent.** Each one's problem shows once you leave it, or when you press Add, in the line under it. Return presses Add; Escape is Cancel. Some services count a refused request against a daily limit (Parcel allows 20 adds a day, refusals included), so a value Legato can tell is wrong never goes out.
- **The service says no.** With `success` and `error`, the service's own reason shows beside Cancel and Add, and the fields stay filled to fix and try again. Legato doesn't retry by itself.
- **It works:** the form closes and the source reads again, as after any button.
- **The form is kept** while you look at other pages or close the panel, until Add works or Cancel. Pressing the button again brings it back.
- **Typed text goes in as a value, never as part of the request's wording.** In the body it's a JSON string, escaped as JSON. A body string that is `"{input.x}"` and nothing else takes the value as it is, so a choice's number stays a number; when an optional field is left empty, that key is left out. Elsewhere in a string it's filled as text, and empty when the field is. Text holding `{secret}` or `{action.id}` arrives as typed: nothing typed is read for placeholders.
- **In the path, only checked values.** A choice can fill the path or a header, since its values are the page's own. A text input can fill the path only with a `pattern`, and it is percent-encoded, so `/`, `?`, `&` or `#` can't change the address. Typed text never fills a header.
- **The request is filled from the inputs** (and `{action.id}`, and any `{answer.…}`) only, as a menu's is from its choice.
- **Spotlight opens the form,** on the button's page, and nothing is sent until Add. **Shortcuts** presses it only when every required input has a `default`; otherwise it says to open the form. **It never goes on a notification.**
- A button with `inputs` can't also have `choices` or `confirm` (Add is the decision), and a checklist's `itemAction` can't have them.

### A form over the page

`"form_style": "card"` opens the form in a card that slides in over the page, under the right end of the title row where Details's card opens, so the page stays in view while you answer. Use it for a short answer about something the page shows, such as a category for one transaction from a row's button:

```json
{ "label": "Choose category", "icon": "pencil", "form_style": "card", "submit": "Save",
  "method": "PUT", "path": "/v2/transactions/{id}",
  "inputs": [ { "name": "category", "label": "Category", "kind": "choice", "required": true,
                "choices": [ { "label": "Groceries", "value": 12 }, { "label": "Household", "value": 31 } ] } ],
  "body": { "category_id": "{input.category}", "status": "reviewed" } }
```

- The card takes the keyboard, so you can type in its fields. Return presses the card's button, except in a long list's filter field, where it picks the highlighted choice without sending.
- The fields are grouped as System Settings groups them: a label and its value on each row, and a field that needs room, such as notes or several picks, in a group of its own under its label.
- Escape or Cancel puts the form away without sending anything. A click elsewhere in the panel does too while nothing has changed, and the click goes on to what it was on, so you can click from one row to the next. Once something has changed, a click elsewhere leaves the form open, so nothing you typed is lost. Clicking another app or the menu bar icon closes the panel as usual and keeps the form: the card is back when the panel opens on its page.
- On a row's button, the card is titled with the row, with the row's amount and grey line under it. A long list's suggestions lead under Suggested, with the search box over every choice below them.
- When the service says no, the card stays open with its reason, as the form in the page's place does.
- Everything else is the same as in the page's place. `"form_style": "page"` is the default, and only a button with `inputs` can have `form_style`.

### Edit forms

A form can open on what's there now and send back only what you change. Give each input a `start`, read from the row for a row's button or from the card's answer for a card's button, and the button `"send": "changed"`. This is the Transactions page's edit form, opened with a click on the row (`"row_actions_place": "row"`):

```json
{ "label": "Edit transaction", "icon": "pencil", "method": "PUT", "path": "/v2/transactions/{id}",
  "form_style": "card", "submit": "Save", "send": "changed",
  "inputs": [
    { "name": "category", "label": "Category", "kind": "choice", "start": "category_id",
      "choices": { "each": "cats.categories", "fields": { "label": "name", "value": "id", "group": "group_name" } } },
    { "name": "payee", "label": "Payee", "start": "payee", "max": 140 },
    { "name": "reviewed", "label": "Reviewed", "kind": "toggle", "start": "status",
      "on_value": "reviewed", "off_value": "unreviewed" },
    { "name": "notes", "label": "Notes", "lines": 4, "start": "notes", "max": 200 },
    { "name": "tags", "label": "Tags", "kind": "choice", "multiple": true, "start": "tag_ids",
      "choices": { "each": "tags.tags", "fields": { "label": "name", "value": "id" } } } ],
  "body": { "category_id": "{input.category}", "payee": "{input.payee}", "status": "{input.reviewed}",
            "notes": "{input.notes}", "tag_ids": "{input.tags}" } }
```

- A text field opens on the value as text, and a choice on the choice with that value. Several picks open on the values in a list that are also choices. A toggle opens on when the value is its `on_value` or `true`.
- With `"send": "changed"`, Save stays dimmed until something differs from what the form opened on. Only the changed fields go out: the other keys are left out of the body, so the form never writes back a value nobody touched. A field you empty on purpose goes as empty: `""` for text, `null` for a choice, `[]` for several picks.
- When the row changed at the service since the form opened, nothing is sent and the card says so.
- Leave out `send` (or write `"send": "all"`) when the request replaces the whole thing, such as Pi-hole's list of upstream servers: every field goes, its `start` only filling the form.

### Choices from the answer

A choice input can list what the card's answer holds instead of fixed choices, such as a budget's categories. Give `choices` a list rule, as a map's `items` takes, with `label`, `value` and, if you like, `group`:

```json
{ "name": "category", "label": "Category", "kind": "choice", "required": true,
  "choices": { "each": "cats.categories",
               "where": { "all": [ { "path": "archived", "equals": false }, { "path": "is_group", "equals": false } ] },
               "fields": { "label": "name", "value": "id", "group": "group_name" } } }
```

- The list is read when the form opens, from the answer the card shows, so the request that fills it goes in the card's source, beside the others. Up to 500 choices, in the answer's order; each group is a heading in the menu.
- When the form is sent, the answer is read again, and a value that has left the list since is refused.
- Past 24 choices the menu becomes a search box over a short list. Typing narrows it to the choices whose label holds what you type, the arrow keys move through what shows, and Return picks one without sending the form.
- A choice made from the answer can't have a `default` or a `guess`. If it’s required, open the form to pick a value. Shortcuts can omit an optional choice when it presses the button. Its values come from the service, so they can fill the path or the body, never a header.

On a row's button, `suggest` reads the row for the values worth offering first, such as the categories an agent thinks fit:

```json
"suggest": { "each": "custom_metadata.legato.choices", "fields": { "value": "category_id" } }
```

The suggestions show as chips above the menu, and the first one is picked when the form opens. Only values that are also on the input's list count, up to 6, and they take the list's labels, so a row can't add a choice or name one differently. Picking a chip or a menu entry sets the same value.

### A switch in the form

A `toggle` is on or off, so it's never `required`, and its `default` is `true` or `false` (off unless set). It fills one JSON body value whole, written exactly `"{input.name}"`: never the path, a header, a form field or part of a longer text, and a form that opens a page can't have one. Numbers in `on_value` and `off_value` must be whole numbers up to 9007199254740991, or have a fraction. This one adds a tag when it's on and leaves the tags alone when it's off:

```json
{ "name": "remember", "label": "Remember for this payee", "kind": "toggle", "on_value": [77] }
```

with `"additional_tag_ids": "{input.remember}"` in the body. A list or true/false filling a body value whole goes out as JSON.

### Forms that open a page

A form can open one of your pages with what was typed, instead of sending a request: a search. Give an `open` button `inputs`, and make its `url` a link to the page, with each `{input.name}` as a whole value of the link's query. This is the Paperless page's Search Paperless:

```json
{ "kind": "open", "label": "Search Paperless", "icon": "magnifyingglass",
  "url": "legato://page/paperless-search?q={input.q}",
  "inputs": [ { "name": "q", "label": "Search", "required": true, "max": 200, "placeholder": "Words, or tag:bills" } ],
  "submit": "Search" }
```

The page it opens takes the value as a [param](https://legatobar.com/docs/detail-pages.md#one-page-for-every-item) of type `query`, `"params": { "q": { "type": "query", "example": "insurance" } }`, and its source asks the service with it: `/api/documents/?query={param.q}&page_size=25`.

- **What was typed goes in the link as one value,** percent-encoded, so `tag:bills "late fee" & more` arrives as typed and can't add a name to the link or reach another page. The page checks it as its param, and when it refuses the value, the form stays open and says why.
- **Every input is required,** since a page link takes every value. The link names one of your pages, its id and names written out; only the values come from the form.
- **Search sends the form and shows the page,** as a card's link does: the form closes, and Back returns to the page you searched from. Nothing is sent to the button's own source.
- **It stays on a card with nothing to show,** as Add Event does: an empty inbox is still worth searching from.
- **Spotlight opens the form,** as for any button with `inputs`. It never goes on a notification.



---

# Rows and checklists

### One action per checklist row

A [checklist](https://legatobar.com/docs/card-lists.md#checklist) whose `items` are mapped with `each` can carry an `itemAction` next to its `actions`: one action object, with the same fields as a button, that runs for the row you tick. Its `path`, `body` strings and `headers` are templates filled from that row of the source's answer, so `{id}` is the task's own id. This is the Todoist page's checklist, which closes a task:

```json
{ "id": "due-now", "type": "checklist", "label": "Next up", "items": [],
  "source": { "ref": "todoist", "map": { "items": { "each": "due.results", "sort": "due.date", "limit": 4,
    "lookup": { "from": "projects.results", "by": "id", "on": "project_id", "as": "project" },
    "fields": { "text": "content", "detail": { "template": "{due.date|day} · {project.name}" }, "done": "checked" } } } },
  "itemAction": { "label": "Complete", "icon": "checkmark", "method": "POST", "path": "/api/v1/tasks/{id}/close" } }
```

A repeating task closed this way moves to its next date, which Todoist works out, and leaves the list once that date is ahead. Closing a parent task closes its subtasks too.

- A row that isn't done shows an empty circle; click it and the request goes out with that row's values. Done rows don't fire. The `label` names the action for VoiceOver and the row's tooltip.
- A value filled into the `path` is percent-encoded, so an id holding `/` or `?` can't name another route. Body strings and header values are filled as they are. The filled path must still start with `/`.
- `when` tests the row rather than the whole answer: `{ "path": "priority", "gt": 1 }` leaves low-priority rows plain.
- With [`graphql`](https://legatobar.com/docs/buttons.md#buttons-that-send-graphql) in place of `body`, a tick sends a GraphQL mutation: the row fills its `variables`, and there a string that is one placeholder alone keeps its type, as on a row's button.
- A row the answer leaves without a value for a placeholder gets no request; the Source Preview window lists such rows under Issues, so you can see it before a tick does nothing.
- The row spins until the source answers again (at most a minute), then shows whatever the service now says: the task gone, or ticked. Success, failure reasons, cooldowns and sign-in all work as for a button.

With `"mark": "switch"`, the rows are things that are on or off, and a press acts on a row that's on as well as one that's off, so one toggle request serves both. This is a Home Assistant card of the lights that are on, each with a bulb that turns it off; its source's template answers `lights_on` as a list of `{ "name", "id", "on" }`:

```json
{ "id": "lights", "type": "checklist", "label": "Lights on", "mark": "switch", "items": [],
  "source": { "ref": "home-assistant", "map": { "items": { "each": "lights_on", "limit": 20,
    "fields": { "text": "name", "done": "on", "icon": { "template": "lightbulb" } } } } },
  "itemAction": { "label": "Turn off", "method": "POST", "path": "/api/services/light/toggle",
    "body": { "entity_id": "{id}" } } }
```

### Sending the row back

Some services replace a whole item with whatever you send: Mealie's shopping items take a `PUT` of the full item, and a body of just `{ "checked": true }` empties its note and quantity. For those, add `"body_from": "row"`. The tick then sends the row's element as the service sent it, with the fields in `body` laid over it:

```json
"itemAction": { "label": "Tick", "icon": "checkmark", "method": "PUT",
  "path": "/api/households/shopping/items/{id}", "body_from": "row", "body": { "checked": true } }
```

- The element goes back as it came, nulls and nested objects included. Fields Legato added to the row (a `lookup`) aren't sent, and nothing copied from the row is read for placeholders, so a note that says `{id}` stays as written.
- `body` is an object, and each of its fields replaces the element's field of the same name. Its strings are filled from the row as usual, and `{action.id}` there is the press's id.
- `map.items` must read a request's answer with `each`, not a `derive`d value, and without `entries`, `zip`, `flatten` or `group`, which make new rows. The page won't load otherwise.
- The method is `PUT`, `PATCH` or `POST`. It can't go with `form` or `graphql`, and only a checklist's `itemAction` takes it.
- The element is as the source last answered. If someone changed the item in the service since then, the tick puts back what Legato saw, so give the source a short `every`.
- A body over 256 KB isn't sent: the tick says so.

### Buttons on each row

A [list](https://legatobar.com/docs/card-lists.md#list) or [pacing](https://legatobar.com/docs/card-numbers.md#pacing) card whose `items` are mapped with `each` can carry `row_actions`: up to three places for buttons at the end of every row's first line, each filled from that row. A pacing row's bar and detail line, and a list row's grey line, run the card's full width under them. This is a media server's Now playing card, with Message and Stop on each stream:

```json
{ "id": "now", "type": "pacing", "label": "Now playing", "items": [],
  "source": { "ref": "media", "map": { "items": { "each": "streams",
    "fields": { "key": "id", "label": "title", "value": "minutes", "target": "length" } } } },
  "row_actions": [
    { "label": "Message", "icon": "bubble.left.and.bubble.right", "method": "POST", "path": "/Sessions/{id}/Message",
      "body": { "Header": "Legato", "Text": "{input.text}", "TimeoutMs": 10000 },
      "inputs": [ { "name": "text", "label": "Message", "required": true, "max": 120 } ], "submit": "Send" },
    { "label": "Stop", "icon": "stop.fill", "method": "POST", "path": "/Sessions/{id}/Playing/Stop",
      "confirm": { "message": "Stop {title} for {user}?", "button": "Stop" },
      "when": { "path": "can_control", "equals": true } } ] }
```

- Each button has a button's fields: `label`, `icon`, `method`, `path`, `body`, `headers`, `when`, `success`, `error`, `completion`, `confirm` (`true`, or `message` and `button`), `graphql`, `form` and `inputs` (a [form](https://legatobar.com/docs/button-input.md#buttons-that-ask-for-text)). It needs an SF Symbol `icon`, which is what the row draws; the `label` is its tooltip and what VoiceOver says.
- A bare `{x}` reads that row of the source's answer, as `itemAction` does, so `{id}` is the stream's own id. `{answer.…}` reads the card's whole answer, `{input.…}` what the form sends, and `{action.id}` the press's own id. A row field called `answer`, `input` or `action` is never read: those names come first.
- A value filled into the `path` is percent-encoded and must be a single value: an empty one, `.` or `..` can't go there. In the `body`, a string that is one placeholder alone keeps its type, so a number stays a number, as on a button. **This differs from `itemAction`**, which fills every body value as text.
- `headers` take fixed values only: a row's values never go in a header.
- A row's button can send a GraphQL mutation with [`graphql`](https://legatobar.com/docs/buttons.md#buttons-that-send-graphql) in place of `body`. The row's values go in its `variables`, as in `"variables": { "id": "{id}" }`, and the query goes as written.
- `when` tests the row. A row it fails has no button there, and the button's place stays empty, so the others don't move.
- `"alternate": true` puts a button in the place of the one before it, for the other half of an on/off pair such as Stop and Start. Give the two `when`s that never hold on the same row; if both do, the first one shows. A card can list four buttons this way, in three places: Stop, Start (its alternate), Remove and Delete files. The first button can't be an alternate, and an alternate can't follow another. A row that lacks a value the button needs (a stream with no `user` for Stop's question) shows the button dimmed, saying why, and the Source Preview window lists it under Issues.
- The buttons show under the pointer, with keyboard focus and while one runs; the first line keeps their room the rest of the time, so nothing moves. Give the card `"row_actions_shown": "always"` to show them on every row all the time, as a download queue does. When no row on the card has a button now (no stream can be controlled), the rows take the full width instead. VoiceOver offers them as the row's actions.
- On a list, `"row_actions_place": "detail"` draws the buttons as one small group over the row's detail, such as its amount, and only under the pointer or with keyboard focus. The rows keep no room for them, so the list reads like any list until you point at a row, as in a mail app. It suits rows you mostly read and sometimes answer, such as an agent's questions. The group sits in one white capsule, as a mail app's hover actions do: plain icons, the one under the pointer in a soft round highlight. It can't go with `row_actions_shown` set to `always`, and a pacing card keeps its buttons at the end of the first line.
- On a list, `"row_actions_place": "row"` draws no buttons at all: a click on a row presses the first button that row offers, which usually opens its form, as clicking a message opens it in a mail app. The row lights under the pointer as a link does, and a row that offers no button keeps its `url`. It takes no `row_actions_shown`.
- On a list with `"row_actions_place": "detail"`, put `"|"` between two buttons to draw a thin line. `"row_actions": [{ "label": "Accept", … }, "|", { "label": "Reject", … }, { "label": "Choose category", … }]` sets Accept apart. It goes only between two buttons, never between an alternate and its partner, and takes no place of its own.
- `confirm` asks in the row: its question takes the row's text, and ✕ and ✓ take the icons' place. A form opens in the page's place, titled with the button and the row. Only one question or form is open at a time.
- A question or form acts only on the row it was opened for. When the row changes what it shows (another episode in the same session), the question closes with a note; when the row leaves (the stream ended), it closes quietly. A form's Send says so instead.
- The button spins until the source answers again (at most a minute), as a checklist row does.
- `done_note` (1–12 characters, such as `"Passed"`) is what the row says after the service accepts a press. The words sit where the row's icons were, for two minutes, whenever the pointer is elsewhere, and the row keeps its size. Use it when a press changes nothing else on the row, as with a test that passes. A refused press shows its reason under the card instead, and pressing again clears the words.
- Rows come and go, so row buttons are never offered to Spotlight, Shortcuts or notifications. The card's own `actions` are, as always.
- Not on a checklist (which has `itemAction`), a `shelf` list, a `ring` or `rings` pacing card, or a list with `ask` or `copyable`.



---

# Secrets

<a id="secrets"></a>

A source names a secret by name; the value itself lives in the Mac's Keychain. Add secrets in **Settings → Secrets**, which also lists the secrets your pages need, with the name and host filled in, so you only paste the value.

To keep a value in 1Password instead, see [1Password secrets](https://legatobar.com/docs/1password.md). For Todoist, **Connect** signs in through your browser and saves a [connection](https://legatobar.com/docs/source-requests.md#connections) instead of a token.

- A secret's name is 1–48 lowercase letters, digits and hyphens. Settings → Secrets saves no other names, so a page that names `my_api` can never be filled; call it `my-api`.
- Each secret is tied to **one host**. Legato sends it only to that host, so a page can't point a secret at another server. One name can be saved for several hosts, each with its own value: a [host list](https://legatobar.com/docs/source-requests.md#several-hosts-from-a-list) sends each host the one saved for it.
- Secret values are sent only to their configured service, when a request needs them. The `legato` tools and MCP server never read or return them, and they aren't in the page file. Agents can [list secrets, change their expiry dates and delete them](https://legatobar.com/docs/mcp-tools.md#secrets) without seeing a value.
- Save source secrets in Settings → Secrets, or with `Legato secret` below. Legato reads only its own source-secret records in the Keychain. A changed app signature or Keychain access restriction can prevent the current build from reading a saved item; if the card says "This build of Legato can't read the secret", save it again in Settings → Secrets.
- Use the least access a service offers: a Pi-hole app password rather than its admin password, and an Uptime Kuma API key rather than a login.

### From 1Password

A secret's value can stay in 1Password instead. In Settings → Secrets, add it with **+** (or **Set…**), choose **1Password** under **Value from** and give the item's reference, such as `op://Legato/Pi-hole/password` (in 1Password, **Copy Secret Reference** from a field's menu). Legato reads the value when a source needs it, with a [1Password service account](https://www.1password.dev/service-accounts) saved in the same tab (**Set Up…** beside 1Password), through Legato's own 1Password helper (nothing else to install). [Secrets from 1Password](https://legatobar.com/docs/1password.md) walks through setting it up. A secret in two parts, such as an OAuth client's ID and secret, can come from [two fields](https://legatobar.com/docs/1password.md#a-secret-in-two-fields). From the command line, `Legato secret set --1password` links a reference only when the caller supplies the same service account token saved in Legato. Saved references use the token saved now.

- The page still names only the secret (`"secret": "pihole"`). Which 1Password item it is, and the host it's sent to, are set in Settings, never by a page, so a page can't ask for another item or send one elsewhere.
- Legato keeps the value in memory and reads it again every hour, and at once when the service refuses it, so a rotated credential reaches the cards on its own. If 1Password can't be reached, the last value read keeps working for up to a day (unless the service refused it), and Legato tries 1Password again after a minute, then less and less often.
- The service account token is kept in the Keychain and handed to Legato's own 1Password helper on its standard input, never in an environment or on a command line. No `op` tool or Homebrew is needed. Give the service account read access to only the vaults Legato needs.
- A wrong reference, or one the service account can't read, shows when you save it, and on the card with a message saying what's wrong.

### Expiry dates

Some tokens stop working on a set day: a Tailscale API access token lasts 90 days at most, and a GitHub fine-grained token as long as you chose. Save that day with the secret and a page can warn you before it comes.

- In Settings → Secrets, tick **Expires** and pick the day when you add or replace a secret. To change only the day, right-click the secret and choose **Set Expiry…**. From the command line, add `--expires 2027-02-09` (or `--expires 90d`) to `secret set`, or run `secret expires`.
- From 14 days before that day, the secret's status is **Needs attention**, and hovering over it says how many days are left.
- Saving a new value takes the day shown in the sheet, or none. A day kept from the old token would warn at the wrong time.
- A page reads only the day, through its source's [`secret_expires`](https://legatobar.com/docs/source-reference.md#source-and-page-reference), and counts down to it with the [`expires` rule](https://legatobar.com/docs/mapping-expiry.md#expiry).
- For a 1Password secret, the day is kept in Legato, not 1Password. If you rotate the item in 1Password, change the day in Legato too.

### From the command line, or an agent

The Legato app is also a command, for scripts, password managers and AI agents that already hold a credential. It reads the value from standard input, never from an argument, so the secret stays out of shell history and the process list, and saves it to the Keychain exactly as Settings → Secrets would.

Nothing is sent anywhere: the value goes to the Keychain, and cards that were waiting for it try again at once.

```bash
# Typed: the value isn't echoed
/Applications/Legato.app/Contents/MacOS/Legato secret set lunch-money

# From 1Password, without the value passing through anything else
op read 'op://Private/Lunch Money/credential' | /Applications/Legato.app/Contents/MacOS/Legato secret set lunch-money
```

| Command | Does |
| --- | --- |
| `Legato secret set NAME [--host HOST] [--replace]` | Saves the value read from standard input. `HOST` defaults to the host of the page that names `NAME`, so write the page first. A secret that's already saved needs `--replace`. |
| `Legato secret set NAME --1password REFERENCE [--1password REFERENCE] [--host HOST] [--replace]` | Links a [1Password reference](https://legatobar.com/docs/1password.md#from-the-command-line-or-an-agent) instead of a value, only with the same `OP_SERVICE_ACCOUNT_TOKEN` saved in Legato. Twice for a [secret in two fields](https://legatobar.com/docs/1password.md#a-secret-in-two-fields). |
| `Legato secret set NAME … --expires DATE` | Saves the expiry date with the secret: `2027-02-09`, or `90d` for 90 days from today. Without it, a new value has no date. |
| `Legato secret expires NAME DATE\|none [--host HOST]` | Changes or clears only the expiry date. |
| `Legato secret list` | Saved secrets by name and host (`from 1Password` for a reference), with their expiry dates and the pages that use each, then the ones your pages name that aren't saved yet. Values are never shown. |
| `Legato secret delete NAME [--host HOST]` | Removes a saved secret. |
| `Legato secret token set [--replace]` / `token delete` | Saves (or removes) the [1Password service account token](https://legatobar.com/docs/1password.md#the-service-account-token-from-the-command-line), read from standard input. |

An agent setting up a page for you writes the page, then runs `secret set` with the credential piped in from wherever it holds it, then `secret list` to check nothing is missing.



---

# Lists

<a id="lists"></a>

A page that checks a place, such as where a package was delivered, shouldn't carry your town in its file: a page shared as a download would then have it in. Instead, keep the words or places in a named list in **Settings → Lists**, on this Mac, and the page names the list with an [`in_list`](https://legatobar.com/docs/mapping-conditions.md#conditions) condition. A page can also send a list's entries to a service, such as the symbols on a stock watchlist. See [Sending a list](#sending-a-list).

- A list's name is 1–48 characters: `a–z`, `0–9` and `-`, starting with a letter or digit, such as `delivery-area`.
- Each entry is plain text, such as "Fernhollow, ST", never a pattern.
- A value matches when it contains any entry as whole words, whatever the case, accents or punctuation.
- Lists are kept in Settings on this Mac, never in a page file, so a page you share or download names the list and holds no one's places.
- A list that's only checked with `in_list` never leaves the Mac. A list a page sends goes to that page's service each time the page reads it, and Settings → Lists shows where.
- A missing or empty list reads false unless `if_missing` is true, and the page still says where to add it, unless the condition is `optional`.
- An agent can set a list for you with the MCP tool `set_list`, or `legato lists set` from a shell. See [Lists and History](https://legatobar.com/docs/mcp-tools.md#lists-and-history).

## Sending a list

Some services answer one item at a time, such as a stock quote, or take a list of ids in one request, such as coin prices. A named request can send a list's entries:

```json
"requests": {
  "quotes": { "path": "/api/v1/quote?symbol={entry}", "each_entry": { "list": "stock-watchlist", "max": 30 } },
  "prices": { "path": "/api/v3/simple/price?ids={entries}&vs_currencies=usd", "all_entries": { "list": "coins" } }
}
```

- `each_entry` sends the request once for each entry, with `{entry}` filled in. `all_entries` sends it once, with every entry in place of `{entries}`, separated by commas.
- Entries go in the request's path or query, encoded, and nowhere else. An entry that isn't a plain symbol or id isn't sent.
- While the list is missing or empty, nothing is sent, and the page says to add the list in Settings → Lists.
- When you edit the list, the page reads the service again right away.
- In **Settings → Lists**, the **Used by** column names the service: "Stocks · sent to finnhub.io".

[Requests from a list](https://legatobar.com/docs/source-requests.md#requests-from-a-list) has the details.



---

# Troubleshooting

<a id="troubleshooting"></a>

| What you see | Check |
| --- | --- |
| No page | Confirm Legato is running, the file is inside `~/Library/Application Support/Legato/Pages/`, and its name ends in `.json` and doesn't start with a dot. Choosing a file in Source Preview previews it without installing it. If the page still doesn't appear, read its [status file](https://legatobar.com/docs/page-loading.md#status-files). After the trial, pages show again once there's a [license](https://legatobar.com/docs/license.md). |
| No editor suggestions | Use a JSON Schema-aware editor, keep the `$schema` line, and open Legato to install `Pages/.schemas/page.schema.json`. If editing outside Pages, adjust the schema location. |
| File or source error | Use a complete page, not a reference fragment. Check JSON syntax, the source name used by `ref`, and that every sourced card has a `map`. |
| HTTP 401 or 403 | Check the API's authentication scheme, the secret's name and host, token permissions, and required version or Accept headers. Login headers belong in `auth.request.headers`. |
| Rate limit or “asked Legato to wait” | Let the shown cooldown expire. It is shared by polling, Fetch Once and buttons for the same origin and credentials. Increase `every` if limits recur; a blocked button needs another click after the wait. |
| “Didn't send JSON” | Check the endpoint returns API JSON rather than a web page or sign-in form. Use `format: "text"` only if you want to display the entire text answer. |
| Missing or unexpected card values | Right-click the page → **Preview Source…** and preview a sample. Check mapping issues and Mapped card JSON. Named requests add a name prefix; lists evaluate paths relative to each item. |
| No usable Prometheus samples | Check `/metrics`, credentials, and the `group_by` label. HTML and empty results are not valid metric data. |
| Secret missing or unreadable | Save it for the configured host in Settings → Secrets. A different app signature or Keychain restriction may require saving it again. |
| Cards show dashes, and no error | The service may report errors in a 200 answer. Right-click the page → **Preview Source…** and Fetch Once to see it, then give the source [`fail`](https://legatobar.com/docs/source-polling.md#when-the-answer-reports-an-error). |
| A button succeeds but the card has not changed | Check the command response, any `success` condition, and subsequent source errors. An accepted command can take time to affect the device. |
