# Widget API

> Read your sites' numbers from a phone widget, a Stream Deck, a status bar or a script, with a personal read token or OAuth, in four views ready to draw.

Source: https://mettr.app/docs/widget-api

The widget API is read only and belongs to a person, not a site: one widget may show sites of several teams. The server works out what to show; a client only draws one of four views, so every widget reads the same numbers as the dashboard.

## Signing in

Every request carries `Authorization: Bearer …`, never a token in the address:

- a **read token** (`mt_read_…`), for scripts and devices with no browser to sign in with: made under **Settings**, **Connected apps**, shown once, limited to the sites you pick, revocable;
- an app's **OAuth access token**: authorization code with PKCE against mettr (`/.well-known/oauth-authorization-server` names the endpoints), scope `read`, an hour's token renewed with its refresh token.

Either way it reads only your teams' sites, and leaving a team ends it at once. No token, a wrong one, or one without a reading scope: `401`. A site you cannot read: `404`, as one that does not exist. 120 requests a minute per token.

Answers carry an `ETag`: send it back as `If-None-Match`, and an unchanged answer is an empty `304`.

```bash
curl https://mettr.app/api/v1/widgets/sites \
  -H "Authorization: Bearer $METTR_READ_TOKEN"
```

## Ranges

Every widget answer takes `period` (`30m`, `1h`, `6h`, `12h`, `24h`, `7d`, `14d`, `30d`, `90d`; when none, the panel's own range, as **Views, last hour** has, else `24h`), or `from` and `until`, instants in UTC as `2026-11-26T14:00:00.000Z`, `until` not included. Days are the site's own.

## Endpoints

### GET /api/v1/sites

The sites, for a widget's settings.

```json
{"sites": [{"id": 7, "name": "Docs", "domains": ["docs.example"], "timezone": "Europe/Kyiv", "team": "Acme"}]}
```

### GET /api/v1/sites/{site}/panels

The site's panels that draw as a widget (built in and your own; a map or a feed has no widget form), and the view each takes.

```json
{"panels": [{"id": "views", "label": "Views", "kind": "total", "view": "number"}, {"id": "p12", "label": "Sign-ups", "kind": "total", "view": "number"}]}
```

### GET /api/v1/sites/{site}/panels/{panel}

One panel, ready to draw. Every answer has `label`, `site` (`id`, `name`), `view`, `refresh` (seconds until it is worth asking again) and `generated_at`, plus the view's fields below. On the dashboard, a panel's **…** menu, **Use as widget**, gives its address.

### GET /api/v1/widgets/sites?sites=7,3

A row per site, at most 20: the ones named, in that order, or every site the token reads, by name.

## Views

**number**: a value against its usual. `change` is in percent, null without a usual; `series` is the sparkline, oldest first, null where a share or an average had nobody to read (a bounce rate in a minute without visits).

```json
{"view": "number", "value": 653, "baseline": 680, "change": -4, "unit": null, "series": [12, 30, 8]}
```

**list**: labelled rows, largest first for a top list, in order for visit depth or a funnel.

```json
{"view": "list", "unit": "ms", "rows": [{"label": "/search", "value": 541}]}
```

**chart**: buckets and series over them. `stacked` series add up to the bar; otherwise the second series is the comparison. Buckets are UTC instants for minutes and hours, the site's dates (`2026-11-26`) for days. A share or an average by the minute goes `step` (5) minutes a bucket, and has null where nobody came.

```json
{"view": "chart", "grain": "hour", "stacked": false, "buckets": ["2026-11-26T13:00:00Z"], "series": [{"label": "Views", "values": [40]}, {"label": "Comparison", "values": [35]}]}
```

**sites**: a row per site. `url` opens the site's dashboard.

```json
{"view": "sites", "rows": [{"id": 7, "name": "Docs", "domains": ["docs.example"], "online": 15, "views": {"value": 653, "baseline": 680, "change": -4}, "visitors": 199, "series": [12, 30, 8], "url": "https://mettr.app/dash/acme/sites/docs"}]}
```

## Scriptable

On iPhone and iPad, the [Scriptable](https://scriptable.app) app runs a home screen widget from a script, and a sites widget is a single call to `/api/v1/widgets/sites`: a row per site with its icon (`https://{domain}/apple-touch-icon.png`), its sparkline, who is online and its views against the usual. Keep the read token in the Keychain, not in the script. Native widgets for iOS, macOS and Android, and a Stream Deck plugin, are on the way.
