# 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.

