The API
You finish this chapter able to drive your reader from a script: list feeds, list what is unread, mark things read, organise and refresh — all without a browser. The check is chapter 5's and 7's: the lab did its subscribing, reading, categorising and refreshing through the calls below, and every change was verified by asking again (transcripts t04 to t08).
Two ways to prove who you are
Every call must say who is asking. There are two credentials, and the difference matters.
Your username and password, sent
as HTTP basic auth (curl -u), work
everywhere. They are also your whole
account: a script holding them holds
everything, including the power to
change them. The lab used them exactly
twice in spirit — to subscribe before
it had a key, and to mint the key.
An API key is a long random token that belongs to one user, does one job — being shown by scripts — and can be revoked on its own. Keys are made in the web interface under Settings → API Keys, or through the API itself:
curl -s -u admin:YOUR-PASSWORD -X POST \
http://127.0.0.1:8080/v1/api-keys \
-H 'Content-Type: application/json' \
-d '{"description":"lab script key"}'
{"id":1,"user_id":1,"token":"d75ecf7f…","description":"lab script key",…}
(That token is the lab's throwaway,
printed in transcript t05 in full
because the lab server is a throwaway
too. Treat your own key like a
password: it is one, for everything
except changing your password.)
Afterwards the key travels in a
header, X-Auth-Token, and the
password can go back in the drawer.
The lab's first guess at this call's
address — /v1/users/1/api-keys —
earned a plain 404 page not found,
and the working address hangs off the
signed-in user instead
(transcript t05). The API is
consistent once you see its habit:
things about you live at the top
level (/v1/me, /v1/api-keys,
/v1/feeds), not under your number.
The calls a script actually needs
Who am I — GET /v1/me returns
your whole profile: username, theme,
sorting, entries per page, reading
speed, even mark_read_on_view. The
lab used it as the key's first proof
of life.
Subscribe — POST /v1/feeds with
{"feed_url": "…"} answers
{"feed_id": N} (chapter 5).
List feeds — GET /v1/feeds
answers with every feed and its full
record, category included.
List entries — GET /v1/entries
with filters in the address:
?status=unread, &order=published_at,
&direction=asc. The answer has the
shape the lab kept counting:
total: 3
3 unread - First potatoes are in
Mark read (or unread, or starred)
— PUT /v1/entries with the entry
numbers and the new status:
curl -s -X PUT http://127.0.0.1:8080/v1/entries \
-H 'X-Auth-Token: YOUR-KEY' \
-H 'Content-Type: application/json' \
-d '{"entry_ids":[3],"status":"read"}'
It answers 204 — success with
nothing to say — and the lab's next
list showed the total fallen to 2
(transcript t05).
Organise — POST /v1/categories
mints a shelf; PUT /v1/feeds/{id}
with {"category_id": N} moves a feed
onto it (chapter 7). Refresh —
PUT /v1/feeds/{id}/refresh, also
204, fetches now (chapter 7).
Leave — GET /v1/export pours the
whole subscription list out as OPML
(chapter 9).
Every answer is JSON, errors are JSON
with an error_message worth reading
(chapter 5's refusal was one), and the
status codes mean what they mean
everywhere: 200 and 201 for answers,
204 for done-and-silent, 401 for "who
are you", 404 for "no such address" —
including, as the lab proved, addresses
that merely sound right.
The other doors, honestly
Miniflux also speaks two older sync dialects — the Google Reader API and the Fever API — so that phone and desktop reader apps (the kind that keep their own offline copies) can treat Miniflux as their back end. They are switched on per user, with their own separate password, under Settings → Integrations. This guide does not exercise them: the lab had no such app, and a sync you cannot watch is a sync you cannot verify. They are described here so the settings page holds no mysteries, and chapter 11 counts the arrangement among the honest limits.