# MQTT credentials and offices

> List, make, rotate and revoke the MQTT credentials on your account, and choose the forecast offices a meteorologist or EOC account follows.

API reference · Reference · https://wxalerts.org/docs/api/mqtt-credentials/

Base URL: `https://api.wxalerts.org`

An MQTT credential is a username and password for the broker, so a script or
device of your own can follow your [alerts](/docs/developers/mqtt/alerts/) and
[lightning](/docs/developers/mqtt/lightning/) live. The routes here manage the
credentials. To write a first client, follow
[Subscribe to live alerts over MQTT](/docs/developers/mqtt-quickstart/); the tab
that uses these routes is described in
[Make an MQTT credential or API key](/docs/accounts/credentials/).

All routes are account routes: a signed-in session or the phone's Bearer token,
with the CSRF header on a cookie request that changes something. See
[Sessions, Bearer and CSRF](/docs/api/sign-in/#sessions-bearer-and-csrf) for the shared
rules and errors. Any plan may use them. Responses are `Cache-Control: no-store`.

## `GET /account/mqtt-credentials`

Your credentials, the limit and the connection details. Session or Bearer. Passwords are
never returned here.

| Field | Type | Description |
| --- | --- | --- |
| `limit` | integer | credentials allowed at once. 3 |
| `credentials` | array | your credentials, as below |
| `connection` | object | how to connect, as below |
| `alert_topics` | array of string | the filter for your alerts, `V2/{user_id}/NWS/#`. Every credential of the account may read it |
| `lightning_topics` | array of string | the filter for your lightning, `V2/{user_id}/GLM/#` |

`credentials[]`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | `account-` plus 32 hex characters. Used in the other routes |
| `name` | string | the name you gave it |
| `username` | string | the broker username, `ha-` plus 12 characters |
| `created_at` | string | |
| `last_rotated_at` | string or null | when the password last changed |
| `active` | boolean | `false` once revoked |
| `topic_prefix` | string | the credential's own private topic prefix, `wxalerts/u/<username>/` |

`connection`:

| Field | Type | Description |
| --- | --- | --- |
| `host` | string | `mqtt.wxalerts.org` |
| `port` | integer | 443 |
| `ws_path` | string | `/mqtt` |
| `ws_url` | string | `wss://mqtt.wxalerts.org/mqtt` |
| `transport` | string | always `websockets` |
| `tls` | boolean | always `true` |

```json
{
  "limit": 3,
  "credentials": [ { "id": "account-3f1c9a0b5d7e4c2a8b6f1d0e9c7a5b3d", "name": "node-red", "username": "ha-a1b2c3d4e5f6",
    "created_at": "2026-11-10T14:00:00Z", "last_rotated_at": null, "active": true, "topic_prefix": "wxalerts/u/ha-a1b2c3d4e5f6/" } ],
  "connection": { "host": "mqtt.wxalerts.org", "port": 443, "ws_path": "/mqtt", "ws_url": "wss://mqtt.wxalerts.org/mqtt", "transport": "websockets", "tls": true },
  "alert_topics": ["V2/12345/NWS/#"],
  "lightning_topics": ["V2/12345/GLM/#"]
}
```

## `POST /account/mqtt-credentials`

Makes a credential. Session or Bearer. Answers `201`. The response, and
[rotate](#post-accountmqtt-credentialscredential_idrotate), are the only times the password is shown.

Body (JSON, optional):

| Field | Type | Default | Bounds |
| --- | --- | --- | --- |
| `name` | string or null | a default name | at most 200 characters |

Response `201`: every `credentials[]` field, every `connection` field, `alert_topics` and
`lightning_topics` as above, plus `password` (string, shown once).

| Status | Body | When |
| --- | --- | --- |
| `409` | `{"detail": {"code": "too_many_credentials", "message": "Revoke a credential first: 3 is the most at once.", "limit": 3}}` | already 3 |
| `422` | default list | `name` longer than 200 |

## `POST /account/mqtt-credentials/{credential_id}/rotate`

A new password for one credential. Session or Bearer. The username stays and the old password stops working. No body.
Response `200` has the same shape as creating one, with the new `password`.

| Name | In | Type | Bounds |
| --- | --- | --- | --- |
| `credential_id` | path | string | matches `^account-[0-9a-f]{32}$`, at most 64 characters |

| Status | Body | When |
| --- | --- | --- |
| `404` | `{"detail": {"code": "credential_not_found", "message": "No such MQTT credential."}}` | not one of your credentials |
| `422` | default list | the id does not match the pattern |

## `DELETE /account/mqtt-credentials/{credential_id}`

Revokes a credential. Session or Bearer. Answers `204`. The login stops working at once, any open session on the broker
is ended and its retained topics are cleared. Same `credential_id` bounds and
errors as rotate.

## Forecast offices for meteorologist and EOC accounts

A meteorologist or EOC account can follow the alerts of up to four National
Weather Service forecast offices, in addition to its saved places. The offices
must touch each other. Other accounts see `eligible: false`. The topics are
described under [MQTT alerts feed](/docs/developers/mqtt/alerts/).

## `GET /account/mqtt-wfos`

The account's offices. Session or Bearer. Any account may call it.

| Field | Type | Description |
| --- | --- | --- |
| `eligible` | boolean | the account is a meteorologist or EOC account |
| `limit` | integer | 4 |
| `selected` | array of string | the four letter office ids chosen, such as `KOUN`, sorted |
| `choices` | array of string | offices that may be added now: any office when none is chosen, none at the limit, otherwise the neighbours of a chosen one. Empty when not eligible |

```json
{ "eligible": true, "limit": 4, "selected": ["KOUN"], "choices": ["KAMA", "KFWD", "KICT", "KOHX", "KSHV", "KTSA"] }
```

## `POST /account/mqtt-wfos`

Adds an office. Session or Bearer. Meteorologist and EOC accounts only. Answers `201` when the office is new and `200` when it
was already selected, with the updated state (same shape as the `GET`).

Body:

| Field | Type | Required | Bounds |
| --- | --- | --- | --- |
| `wfo` | string | yes | exactly four letters, `^[A-Za-z]{4}$`. Case does not matter; it is stored upper case |

| Status | Body | When |
| --- | --- | --- |
| `403` | `{"detail": {"code": "not_eligible", "message": "..."}}` | not a meteorologist or EOC account |
| `409` | `{"detail": {"code": "too_many_wfos", "message": "..."}}` | four already |
| `422` | `{"detail": {"code": "unknown_office", "message": "..."}}` | not a forecast office |
| `422` | `{"detail": {"code": "not_adjacent", "message": "..."}}` | it would not touch the offices already chosen |
| `422` | default list | `wfo` is not four letters |

## `DELETE /account/mqtt-wfos/{wfo}`

Removes an office. Session or Bearer. Answers `200` with the updated state. Allowed even after the account
stopped being eligible, so it can clear what it chose.

| Name | In | Type | Bounds |
| --- | --- | --- | --- |
| `wfo` | path | string | `^[A-Za-z]{4}$` |

| Status | Body | When |
| --- | --- | --- |
| `404` | `{"detail": {"code": "wfo_not_selected", "message": "..."}}` | that office is not chosen |
| `409` | `{"detail": {"code": "would_split_selection", "message": "..."}}` | the offices left would no longer be connected |
| `422` | default list | not four letters |
