Jump to content

OpenJournal:API

From openjournal
Revision as of 19:58, 10 September 2026 by OpenJournalAdmin (talk | contribs) (API documentation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

openjournal is MediaWiki, so it has MediaWiki's APIs — nothing here is bespoke, and anything true of the MediaWiki API is true here.

Cross-origin reads are allowed, so you can call these straight from a browser — but MediaWiki only sends the CORS headers when you ask for them, so add &origin=* to any api.php request you make from another site. rest.php needs no such parameter.

Articles are subpages of their author: User:Alice/Some title. That means "everything Alice wrote" is a title-prefix query.

The friendly routes

For the common case -- get someone's posts, get one post -- these read better than the MediaWiki API underneath them, which is all they are: Apache rewrite rules onto the exact same api.php and action=render this page documents further down, not a second API to keep in sync.

GET /users/{username}/posts                     all of a user's posts, alphabetical by title
GET /users/{username}/posts/{title}              one post: title, wikitext, last-edited time
GET /users/{username}/posts/{title}?format=html  the same post, rendered to HTML
GET /users/{username}                            redirects to their journal (browsable)

{title} is the part after the slash, with spaces as underscores, e.g. /users/Alice/posts/Laying_a_hedge for User:Alice/Laying a hedge.

A post that doesn't exist behaves differently depending on the format: with ?format=html you get a real 404. Without it -- the default, plain JSON -- you always get 200, with "missing":true in the body instead. That form is calling api.php underneath, and there is no way to make MediaWiki's own API answer with a different HTTP status without writing code, which this project avoids. Check missing if that matters to you.

All articles by one user (the underlying MediaWiki call)

Same data the /users/{username}/posts route above returns, and where its extra parameters -- excerpts, URLs -- come from, if you want to add your own.

GET /api.php?action=query&list=allpages&apnamespace=2&apprefix=Alice/&format=json

One article, as HTML

GET /rest.php/v1/page/User%3AAlice%2FSome_title/html

One article, as source

GET /rest.php/v1/page/User%3AAlice%2FSome_title

Every article on the site, newest first

GET /api.php?action=query&generator=recentchanges&grcnamespace=2&grclimit=30&format=json

Excerpts and lead images, for a card or a feed

GET /api.php?action=query&prop=extracts|pageimages&exchars=300&explaintext=1&titles=User:Alice/Some_title&format=json

An Atom feed of everything

GET /index.php?title=Special:RecentChanges&feed=atom&namespace=2

One author's feed is the same URL narrowed with &tagfilter= or, more simply, poll list=allpages above.

Writing from your own code

Editing over the API uses the same login you use in the browser, which is Wikimedia OAuth — so a script writes by acting as you through an [https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration owner-only OAuth consumer], not by sending a password. Bot passwords are switched off here for the same reason.

See OpenJournal:API/Recipes for worked examples, or the full parameter reference at Special:ApiHelp/query — it is generated from this wiki's own installed modules, so it is never out of date.