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

