API:REST API/Reference

The history API provides access to the revision history of a wiki page. You can use the history API to explore recent edits to a page, see the HTML for a specific revision, compare versions, and get statistics about the history of the page. The history API is available in MediaWiki 1.35 and later.

Exploring page history
A wiki page's history is divided into a sequence of revisions. A revision can be any change to the content of the page: an anonymous editor correcting a typo, an admin reverting vandalism, a bot fixing a citation link. The history API lets you browse through a page's history in segments of 20 revisions.

To see the 20 most recent revisions to a page, make a request to the page history endpoint, including the page title in the path.

The page history endpoint returns the latest revision segment, starting with the most recent revision. Each revision object includes the revision ID, which you can use with the get HTML and compare revisions endpoints. Revision IDs do not increase sequentially, so you may see an older revision with a higher revision ID than a newer revision.

Let's say we want to look further back in the history of the page. You can use the  URL to fetch the next 20 oldest revisions, not including the revision specified by the   parameter.

In this example, the API does not return a new  URL, indicating that there are no older revisions left to return. Following the same pattern, the absence of a  URL indicates that there are no newer revisions.

From here, you can use the  URL to scroll forward in the page's history, or, by requesting the page history without an   or   parameter, return to the most recent revisions. Remember, the page history endpoint can only return up to 20 revisions, so you cannot use both the  and   parameters in the same request.

To examine a page at any point in its history, use the revision ID to request the HTML from the revision endpoint.

Filtering by revision type
Some revisions are tagged to indicate the type of edit. The page history endpoint supports filtering by edit type, allowing you to request only edits made by bots, only edit made by anonymous users, or only edits that have since been reverted.

To see the most recent edits made by bots, call the page history endpoint with the  query parameter set to.

You can pair the  parameter (set to either ,  , or  ) with the   or   parameters to explore page history by revision type. Due to differences in caching infrastructure, the number of revisions returned by the page history filters may not match the statistics returns by the edit count endpoints.

Comparing revisions
When exploring a page's history, you can use the size and delta to understand the impact of the edit in relation to the previous edit. You can also compare any two revisions line by line using the compare revisions endpoint. The compare revision endpoint takes two revision IDs as path parameters; you can use the page history endpoint to select revision IDs.

To compare revision 388866 to revision 196313, supply the revision IDs in the endpoint path. The API returns a JSON-formatted diff object comparing the two revisions.

Get page history
Returns information about the 20 latest revisions to a wiki page, starting with the latest revision. The revision segment includes API routes for the next oldest, next newest, and latest revisions, letting you scroll through page history. The page history endpoint responds to the presence a logged-in user and displays content appropriate to that user's permissions.

Request examples

Request parameters

Response codes

Response example

Response schema

Get page history counts
Returns historical data about a page's history.

Request examples

Request parameters

Response codes

Response example

Response schema

Get revision
Returns details for an individual revision, including the page HTML.

Request example

Request parameters

Response codes

Response example

Response schema

Compare revisions
Uses the Wikidiff2 extension to return a line-by-line comparison of two revisions. Only text-based wiki pages can be compared; trying to compare revisions of other page types, such as image pages, results in a 400 response code. The compare revisions endpoint responds to the presence a logged-in user and displays content appropriate to that user's permissions.

The compare revisions endpoint requires Wikidiff2 1.9.0 or later.

Request example

Request parameters

Response codes

Response example

Response schema