API:REST API/Reference
The REST API lets you interact with MediaWiki by sending HTTP requests to unique URLs. You can use the API to build apps and scripts that search wiki pages and explore page history.
Search
editMediaWiki version: | ≥ 1.35 |
Search result object
editThe search result object represents a wiki page matching the requested search.
Example
edit{
"id": 38930,
"key": "Jupiter",
"title": "Jupiter",
"excerpt": "<span class=\"searchmatch\">Jupiter</span> is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half",
"matched_title": null,
"description": "fifth planet from the Sun and largest planet in the Solar System",
"thumbnail": {
"mimetype": "image/jpeg",
"size": null,
"width": 200,
"height": 200,
"duration": null,
"url": "//upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Jupiter_and_its_shrunken_Great_Red_Spot.jpg/200px-Jupiter_and_its_shrunken_Great_Red_Spot.jpg"
}
}
Schema
editid
required | integer |
Page identifier
|
key
required | string |
Page title in URL-friendly format
|
title
required | string |
Page title in reading-friendly format
|
excerpt
required | string |
|
matched_title
optional | string |
The title of the page redirected from, if the search term originally matched a redirect page or null if search term did not match a redirect page.
|
description
required | string |
In Wikimedia projects: Short summary of the page topic based on the corresponding entry on Wikidata or null if no entry exists. See Extension:ShortDescription to populate this field in third-party installations.
|
thumbnail
required | object |
Information about the thumbnail image for the page or null if no thumbnail exists.
|
Search pages
editPath | /search/page?q=search terms
|
Method | GET
|
---|---|---|---|
Content type | application/json
|
Returns | pages object containing array of search results
|
Searches wiki page titles and contents for the provided search terms, and returns matching pages.
This endpoint uses the search engine configured in the $wgSearchType configuration setting and returns results in the namespaces configured by $wgNamespacesToBeSearchedDefault.
Examples
editcurl
edit# Search English Wikipedia for up to 20 pages containing information about Jupiter
$ curl "https://en.wikipedia.org/w/rest.php/v1/search/page?q=jupiter&limit=20"
Python
edit# Search English Wikipedia for up to 20 pages containing information about Jupiter
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/search/page'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
'q': 'jupiter',
'limit': '20'
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
print(data)
PHP
edit<?php
/*
Search English Wikipedia for up to 20 pages containing information about Jupiter
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/search/page";
$params = [ "q" => "jupiter", "limit" => "20" ];
$url = $url . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Search English Wikipedia for up to 20 pages containing information about Jupiter
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/search/page";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
let params = {
'q': 'jupiter',
'limit': '20'
};
let query = Object.keys(params)
.map(k => k + '=' + encodeURIComponent(params[k]))
.join('&');
url = url + '?' + query;
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editq
required | query | string |
Search terms |
limit
optional | query | string |
Maximum number of search results to return, between 1 and 100. Default: 50 |
Responses
edit200 | Success: Results found. Returns a pages object containing an array of search results.
|
---|---|
200 | Success: No results found. Returns a pages object containing an empty array.
|
400 | Query parameter not set. Add q parameter.
|
400 | Invalid limit requested. Set limit parameter to between 1 and 100.
|
500 | Search error |
Autocomplete page title
editPath | /search/title?q=search terms
|
Method | GET
|
---|---|---|---|
Content type | application/json
|
Returns | pages object containing array of search results
|
Searches wiki page titles, and returns matches between the beginning of a title and the provided search terms. You can use this endpoint for a typeahead search that automatically suggests relevant pages by title.
This endpoint uses the search engine configured in the $wgSearchType configuration setting and returns results in the namespaces configured by $wgNamespacesToBeSearchedDefault . Results may differ depending on the configured search backend. While the default backend only applies basic case folding and prefix matches, more advanced backends may apply more complex variations. In the case of CirrusSearch for instance, matches are based on the Elastic Search completion suggester.
Examples
editcurl
edit# Search English Wikipedia for up to 5 pages with titles that start with "solar"
$ curl "https://en.wikipedia.org/w/rest.php/v1/search/title?q=solar&limit=5"
Python
edit# Search English Wikipedia for up to 5 pages with titles that start with "solar"
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/search/title'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
'q': 'solar',
'limit': '5'
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
print(data)
PHP
edit<?php
/*
Search English Wikipedia for up to 5 pages with titles that start with "solar"
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/search/title";
$params = [ "q" => "solar", "limit" => "5" ];
$url = $url . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Search English Wikipedia for up to 5 pages with titles that start with "solar"
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/search/title";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
let params = {
'q': 'solar',
'limit': '5'
};
let query = Object.keys(params)
.map(k => k + '=' + encodeURIComponent(params[k]))
.join('&');
url = url + '?' + query;
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editq
required | query | string |
Search terms |
limit
optional | query | string |
Maximum number of search results to return, between 1 and 100. Default: 50 |
Responses
edit200 | Success: Results found. Returns a pages object containing an array of search results.
|
---|---|
200 | Success: No results found. Returns a pages object containing an empty array.
|
400 | Query parameter not set. Add q parameter.
|
400 | Invalid limit requested. Set limit parameter to between 1 and 100.
|
500 | Search error |
Pages
editMediaWiki version: | ≥ 1.35 |
Page object
editThe page object represents the latest revision of a wiki page.
Example
edit{
"id": 9228,
"key": "Earth",
"title": "Earth",
"latest": {
"id": 963613515,
"timestamp": "2020-06-20T20:05:55Z"
},
"content_model": "wikitext",
"license": {
"url": "//creativecommons.org/licenses/by-sa/3.0/",
"title": "Creative Commons Attribution-Share Alike 3.0"
},
"html_url": "https://en.wikipedia.org/w/rest.php/v1/page/Earth/html"
}
Schema
editid
required | integer |
Page identifier
|
key
required | string |
Page title in URL-friendly format
|
title
required | string |
Page title in reading-friendly format
|
latest
required | object |
Information about the latest revision, including:
|
content_model
required | string |
Type of content on the page. See the content handlers reference for content models supported by MediaWiki and extensions.
|
license
required | map of strings |
Information about the wiki's license, including:
|
html_url
required | string (Get page only) |
API route to fetch the content of the page in HTML
|
html
required | string (Get page offline only) |
Latest page content in HTML, following the HTML specification
|
source
required | string (Get page source, create page, and update page only) |
Latest page content in the format specified by the content_model property
|
Page language object
editThe page language object represents a wiki page and its language.
Example
edit{
"code": "pl",
"name": "polski",
"key": "Ziemia",
"title": "Ziemia"
}
Schema
editcode
required | string |
Language code. For Wikimedia projects, see the site matrix on Meta-Wiki.
|
name
required | string |
Translated language name
|
key
required | string |
Translated page title in URL-friendly format
|
title
required | string |
Translated page title in reading-friendly format
|
Create page
editPath | /page
|
Method | POST
|
---|---|---|---|
Accepts | application/json
|
Body | see schema below |
Content type | application/json
|
Returns | Page object with source property
|
Creates a wiki page. The response includes a location
header containing the API endpoint to fetch the new page.
This endpoint is designed to be used with the OAuth extension authorization process.
Callers using cookie-based authentication instead must add a CSRF token
to the request body.
To get a CSRF token, see the Action API.
Examples
editcurl
edit# Create a user sandbox page on English Wikipedia
$ curl -X POST https://en.wikipedia.org/w/rest.php/v1/page -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" --data '{"source": "Hello, world!", "title": "User:<my username>/Sandbox", "comment": "Creating a test page with the REST API"}'
Python
edit# Create a user sandbox page on English Wikipedia
import requests
import json
url = 'https://en.wikipedia.org/w/rest.php/v1/page'
# Substitute your OAuth token
headers = {
'User-Agent' : 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)',
'Content-Type' : 'application/json',
'Authorization': 'Bearer $TOKEN'
}
# Substitute your username
request_data = {
"source" : "Hello, world!",
"title" : "User:<my username>/Sandbox",
"comment": "Creating a test page with the REST API"
}
response = requests.post( url, headers=headers, data = json.dumps(request_data) )
output = response.json()
print(output)
PHP
edit<?php
/*
Create a user sandbox page on English Wikipedia
*/
$url = 'https://en.wikipedia.org/w/rest.php/v1/page';
// Substitute your username
$fields = [
'source' => 'Hello, world!',
'title' => 'User:<my username>/Sandbox',
'comment' => 'Creating a test page with the REST API'
];
$json = json_encode( $fields );
$token = 'YOUR_OAUTH_TOKEN'; // Substitute your OAuth token
$authorization = 'Authorization: Bearer ' . $token;
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' , $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>
JavaScript
edit/*
Create a user sandbox page on English Wikipedia
Substitute your OAuth token for $TOKEN.
Substitute your username for <my username>.
*/
async function doFetch() {
const response = await fetch(
"https://en.wikipedia.org/w/rest.php/v1/page",
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $TOKEN'
},
body: JSON.stringify({
"source" : "Hello, world!",
"title" : "User:<my username>/Sandbox",
"comment": "Creating a test page with the REST API"
}),
'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
);
const data = await response.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Request schema
editsource
required | string |
Page content in the format specified by the content_model property
|
title
required | string |
Page title. See the manual for information about page titles in MediaWiki. |
comment
required | string |
Reason for creating the page. To allow the comment to be filled in by the server, use "comment": null .
|
content_model
optional | string |
Type of content on the page. Defaults to wikitext . See the content handlers reference for content models supported by MediaWiki and extensions.
|
token
optional | string |
CSRF token required when using cookie-based authentication. Omit this property when authorizing using OAuth. |
Responses
edit201 | Success: Page created. Returns page object with source property.
|
---|---|
400 | Missing token when using cookie-based authentication. Add a CSRF token to the request body, or use an OAuth authorization flow.
|
400 | Bad content model. Include a valid content_model based on available content handlers.
|
409 | Page already exists |
415 | Unsupported Content-Type. Add the request header Content-Type: application/json .
|
Update page
editRoute | /page/{title}
|
Content type | application/json
|
---|---|---|---|
Method | PUT
|
Returns | Page object with source property
|
Updates or creates a wiki page.
This endpoint is designed to be used with the OAuth extension authorization process.
Callers using cookie-based authentication instead must add a CSRF token
to the request body.
To get a CSRF token, see the Action API.
To update a page, you need the page's latest revision ID and the page source.
First call the get page source endpoint, and then use the source
and latest.id
to update the page.
If latest.id
doesn't match the page's latest revision, the API resolves conflicts automatically when possible.
In the event of an edit conflict, the API returns a 409 error.
To create a page, omit latest.id
from the request.
Examples
editcurl
edit# Update the sandbox page on English Wikipedia with "Hello, world!"
$ curl -X PUT https://en.wikipedia.org/w/rest.php/v1/page/Wikipedia:Sandbox -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" --data '{"source": "Hello, world!", "comment": "Testing out the REST API", "latest": { "id": 555555555 }}'
Python
edit# Update the sandbox page on English Wikipedia with "Hello, world!"
import requests
import json
url = "https://en.wikipedia.org/w/rest.php/v1/page/Wikipedia:Sandbox"
# Substitute your OAuth token
headers = {
"User-Agent" : "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)",
"Content-Type" : "application/json",
"Authorization" : "Bearer $TOKEN"
}
# Use the get page endpoint to get the latest revision ID
request_data = {
"source" : "Hello, world!",
"comment": "Testing out the REST API",
"latest" : { "id": 555555555 }
}
response = requests.put( url, headers=headers, data = json.dumps(request_data) )
output = response.json()
print(output)
PHP
edit<?php
/*
Update the sandbox page on English Wikipedia with "Hello, world!"
*/
$page = 'Wikipedia:Sandbox';
$endpoint = 'https://en.wikipedia.org/w/rest.php/v1/page/';
$url = $endpoint . $page;
// Use the get page endpoint to get the latest revision ID
$fields = [
'source' => 'Hello, world!',
'comment' => 'Testing out the REST API',
'latest' => [
'id' => 555555555
]
];
$json = json_encode( $fields );
$token = 'YOUR_OAUTH_TOKEN'; // Substitute your OAuth token
$authorization = 'Authorization: Bearer ' . $token;
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'PUT' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>
JavaScript
edit/*
Update the sandbox page on English Wikipedia with "Hello, world!"
Substitute your OAuth token for $TOKEN.
Use the get page endpoint to get the latest revision ID.
*/
async function doFetch() {
const response = await fetch(
"https://en.wikipedia.org/w/rest.php/v1/page/Wikipedia:Sandbox",
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $TOKEN'
},
body: JSON.stringify({
"source": "Hello, world!",
"comment": "Testing out the REST API",
"latest": { "id": 555555555 }
}),
'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
);
const data = await response.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path |
Wiki page title |
Request schema
editsource
required | string |
Page content in the format specified by the content_model property
|
comment
required | string |
Summary of the edit. To allow the comment to be filled in by the server, use "comment": null .
|
latest
optional | object |
Object identifying the base revision of the edit. You can fetch this information from the get page source endpoint. |
latest.id
optional | integer |
Identifier for the revision used as the base for the new source , required for updating an existing page. To create a page, omit this property.
|
content_model
optional | string |
Type of content on the page. Defaults to wikitext for new pages or to the existing page's content model. See the content handlers reference for content models supported by MediaWiki and extensions.
|
token
optional | string |
CSRF token required when using cookie-based authentication. Omit this property when authorizing using OAuth. |
Responses
edit200 | Success: Page updated. Returns page object with source property.
|
---|---|
201 | Success: Page created. Returns page object with source property.
|
400 | Missing token when using cookie-based authentication. Add a CSRF token to the request body, or use an OAuth authorization flow.
|
400 | Bad content model. Ensure that the content_model property in the request body matches the content_model for the target page.
|
409 | Page already exists. To update the existing page, provide the base revision identifier in latest.id in the request body.
|
409 | Edit conflict. The error response includes the differences between the base revision specified in the request and the latest published revision. See the Wikidiff2 docs for information about the diff format. Requires Wikidiff2 extension 1.10+. |
415 | Unsupported Content-Type. Add the request header Content-Type: application/json .
|
Get page
editRoute | /page/{title}/bare
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | Page object with html_url property
|
Returns the standard page object for a wiki page, including the API route to fetch the latest content in HTML, the license, and information about the latest revision.
Examples
editcurl
edit# Get information about the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare"
Python
edit# Get information about the Jupiter article on English Wikipedia
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get information about the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get information about the Jupiter article on English Wikipedia
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/bare";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path |
Wiki page title |
Responses
edit200 | Success: Page found. Returns page with html_url property.
|
---|---|
301 |
Title normalization redirect |
404 | Title or revision not found |
Get page offline
editRoute | /page/{title}/with_html
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | Page object with html property
|
Returns information about a wiki page, including the license, latest revision, and latest content in HTML.
Examples
editcurl
edit# Get HTML and metadata for the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html"
Python
edit# Get HTML and metadata for the Jupiter article on English Wikipedia
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get HTML and metadata for the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get HTML and metadata for the Jupiter article on English Wikipedia
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/with_html";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path | string |
Wiki page title |
redirect
optional | query | bool |
Set to no to not follow wiki redirects.
|
Responses
edit200 | Success: Page found. Returns page with html property.
|
---|---|
301 | Title normalization redirect |
307 | Wiki redirect |
404 | Title or revision not found |
Get page source
editRoute | /page/{title}
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | Page object with source property
|
Returns the content of a wiki page in the format specified by the content_model
property, the license, and information about the latest revision.
Examples
editcurl
edit# Get source and metadata for the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter"
Python
edit# Get source and metadata for the Jupiter article on English Wikipedia
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get source and metadata for the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get source and metadata for the Jupiter article on English Wikipedia
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path |
Wiki page title |
Responses
edit200 | Success: Page found. Returns page with source property.
|
---|---|
301 |
Title normalization redirect |
404 | Title or revision not found |
Get HTML
editRoute | /page/{title}/html
|
Content type | text/html
|
---|---|---|---|
Method | GET
|
Returns | Page HTML in HTML format |
Returns the latest content of a wiki page in HTML.
Examples
editcurl
edit# Get the content of the Jupiter article on English Wikipedia in HTML
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html"
Python
edit# Get the content of the Jupiter article on English Wikipedia in HTML
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get the content of the Jupiter article on English Wikipedia in HTML
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get the content of the Jupiter article on English Wikipedia in HTML
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/html";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path | string |
Wiki page title |
redirect
optional | query | bool |
Set to no to not follow wiki redirects.
|
Responses
edit200 | Success. Returns page HTML in HTML format. |
---|---|
301 | Title normalization redirect |
307 | Wiki redirect |
404 | Title or revision not found |
Get languages
editRoute | /page/{title}/links/language
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | Array of page languages |
Searches connected wikis for pages with the same topic in different languages. Returns an array of page language objects that include the name of the language, the language code, and the translated page title.
Examples
editcurl
edit# Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language"
Python
edit# Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Find articles from other Wikipedias linked to the Jupiter article on English Wikipedia
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/language";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path |
Wiki page title |
Responses
edit200 | Success: Languages found. Returns array of page languages. |
---|---|
404 | Title not found |
Get files on page
editRoute | /page/{title}/links/media
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | files object containing array of files
|
Returns information about media files used on a wiki page.
Examples
editcurl
edit# Get media files used on the Jupiter article on English Wikipedia
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media"
Python
edit# Get media files used on the Jupiter article on English Wikipedia
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get media files used on the Jupiter article on English Wikipedia
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get media files used on the Jupiter article on English Wikipedia
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/links/media";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path |
Wiki page title |
Responses
edit200 | Success: Media files found. Returns files object containing array of files.
|
---|---|
200 | Success: No media files found. Returns files object containing an empty array.
|
404 | Title not found |
400 | Page contains more than 100 media files |
Transform
editMediaWiki version: | ≥ 1.41 |
The transform endpoint provides on-the-fly round-trip conversion between wikitext and HTML.
Convert Wikitext to HTML
editRoute | /transform/wikitext/to/html/{title}
|
Content type | application/json
|
---|---|---|---|
Method | POST
|
Payload | Transform request body with source
|
Returns | an HTML document. |
Converts wikitext to HTML.
Examples
editcurl
edit# Render wikitext in the context of the Jupiter page on English Wikipedia, without modifying the page:
$ curl -X POST -H "Content-Type: application/json" --data '{ "wikitext": "== Hello Jupiter ==" }' 'https://en.wikipedia.org/w/rest.php/v1/transform/wikitext/to/html/Jupiter'
Parameters
edittitle
required | path |
Wiki page title, used for context |
Responses
edit200 | Success: the response body contains the rendered HTML. |
---|
Convert HTML to Wikitext
editRoute | /transform/html/to/wikitext/{title}
|
Content type | application/json
|
---|---|---|---|
Method | POST
|
Payload | Transform request body with HTML
|
Returns | a wikitext document. |
Converts wikitext to HTML.
Examples
editcurl
edit# Generate wikitext from HTML, in the context of the Jupiter page on English Wikipedia:
$ curl -X POST -H "Content-Type: application/json" --data '{ "html": "<h2> hello World </h2>" }' 'https://en.wikipedia.org/w/rest.php/v1/transform/html/to/wikitext/Jupiter'
Parameters
edittitle
required | path |
Wiki page title, used for context |
Responses
edit200 | Success: the response body contains the wikitext. |
---|
Transform request body
editPayload structure for transform requests.
Example
editFor converting wikitext to HTML:
{
"wikitext": "Hello World"
}
For converting HTML to Wikitext:
{
"html": "<h2>Hello World</h2>"
}
Media files
editMediaWiki version: | ≥ 1.35 |
File object
editThe file object represents a file uploaded to a wiki.
Example
edit{
"title": "The Blue Marble.jpg",
"file_description_url": "//commons.wikimedia.org/wiki/File:The_Blue_Marble.jpg",
"latest": {
"timestamp": "2011-12-07T05:11:41Z",
"user": {
"id": 811185,
"name": "Ultimate Roadgeek"
}
},
"preferred": {
"mediatype": "BITMAP",
"size": null,
"width": 599,
"height": 599,
"duration": null,
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/The_Blue_Marble.jpg/599px-The_Blue_Marble.jpg"
},
"original": {
"mediatype": "BITMAP",
"size": 7011595,
"width": 3000,
"height": 3002,
"duration": null,
"url": "https://upload.wikimedia.org/wikipedia/commons/7/78/The_Blue_Marble.jpg"
},
"thumbnail": {
"mediatype": "BITMAP",
"size": null,
"width": 1023,
"height": 1024,
"duration": null,
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/The_Blue_Marble.jpg/1023px-The_Blue_Marble.jpg"
}
}
Schema
edittitle
required | string |
File title |
file_description_url
required | string |
URL for the page describing the file, including license information and other metadata |
latest
required | object |
Object containing information about the latest revision to the file, including:
|
preferred
required | object |
Information about the file's preferred preview format, original format, and thumbnail format, including:
|
original
required | object | |
Get file only
required | object |
Get file
editRoute | /file/{title}
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | File |
Returns information about a file, including links to download the file in thumbnail, preview, and original formats.
Examples
editcurl
edit# Get File:The_Blue_Marble.jpg on Wikimedia Commons
$ curl "https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg"
Python
edit# Get File:The_Blue_Marble.jpg on Wikimedia Commons
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get File:The_Blue_Marble.jpg on Wikimedia Commons
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get File:The_Blue_Marble.jpg on Wikimedia Commons
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/file/File:The_Blue_Marble.jpg";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editparameter | description |
---|---|
title
required | path |
File title |
Responses
edit200 | Success: file found. Returns file. |
---|---|
404 | Title not found |
History
editMediaWiki version: | ≥ 1.35 |
Revision object
editThe revision object represents a change to a wiki page.
Example
edit{
"id": 931281281,
"page": {
"id": 38930,
"title": "Jupiter"
},
"size": 126009,
"minor": false,
"timestamp": "2019-12-18T01:39:24Z",
"user": {
"id": 27015025,
"name": "InternetArchiveBot"
},
"comment": "Bluelinking 2 books for [[WP:V|verifiability]].) #IABot (v2.1alpha3",
"delta": 231
}
Schema
editid
required | integer |
Revision identifier |
Get revision only
required | object |
Object containing information about the page, including:
|
user
required | object |
Object containing information about the user that made the edit, including:
For anonymous users, the |
timestamp
required | string |
Time of the edit in ISO 8601 format |
comment
required | string |
Comment or edit summary written by the editor. For revisions without a comment, the API returns null or "" .
|
size
required | integer |
Size of the revision in bytes |
delta
required | integer |
Number of bytes changed, positive or negative, between a revision and the preceding revision (example: -20 ). If the preceding revision is unavailable, the API returns null .
|
minor
required | boolean |
Set to true for edits marked as minor |
html_url
required | string (Get revision only) |
API route to fetch the content of the revision in HTML
|
html
required | string (Get revision with HTML only) |
Revision content in HTML, following the HTML specification
|
source
required | string (Get revision source only) |
Revision content in the format specified by the content_model property
|
Get page history
editRoute | /page/{title}/history
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | Page history segment |
Returns information about the latest revisions to a wiki page, in segments of 20 revisions, starting with the latest revision. The response includes API routes for the next oldest, next newest, and latest revision segments, letting you scroll through page history.
Examples
editcurl
edit# Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history?filter=bot&older_than=939967546"
Python
edit# Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
'filter': 'bot',
'older_than': '939967546'
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
print(data)
PHP
edit<?php
/*
Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history";
$params = [ "filter" => "bot", "older_than" => "939967546" ];
$url = $url . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get revisions made to the Jupiter article on English Wikipedia by bots prior to revision 939967546
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
let params = {
'filter': 'bot',
'older_than': '939967546'
};
let query = Object.keys(params)
.map(k => k + '=' + encodeURIComponent(params[k]))
.join('&');
url = url + '?' + query;
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path |
Wiki page title |
older_than
optional | query |
Accepts a revision ID. Returns the next 20 revisions older than the given revision ID. |
newer_than
optional | query |
Accepts a revision ID. Returns the next 20 revisions newer than the given revision ID. |
filter
optional | query |
Filter that returns only revisions with certain tags, one of:
The API supports one filter per request. |
Responses
edit200 | Success: Revisions found. Returns a page history segment. |
---|---|
200 | Success: No revisions found. Returns a page history segment with an empty revisions array.
|
400 | Revision identifier must be greater than 0 |
400 | Parameters older_than and newer_than cannot both be specified
|
400 | Invalid parameter |
404 | Title or revision not found |
Response schema
editlatest
required | string |
API route to get the latest revisions |
older
optional | string |
If available, API route to get the prior revisions |
newer
optional | string |
If available, API route to get the following revisions |
revisions
required | array |
Array of 0-20 revision objects |
Get page history counts
editRoute | /page/{title}/history/counts/{type}
|
Content type | application/json
|
---|---|---|---|
Method | GET
|
Returns | History count object |
Returns data about a page's history.
Examples
editcurl
edit# Get the number of edits to a page between revisions 384955912 and 406217369
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits?from=384955912&to=406217369"
Python
edit# Get the number of edits to a page between revisions 384955912 and 406217369
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
'from': '384955912',
'to': '406217369'
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
print(data)
PHP
edit<?php
/*
Get the number of edits to a page between revisions 384955912 and 406217369
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits";
$params = [ "from" => "384955912", "to" => "406217369" ];
$url = $url . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get the number of edits to a page between revisions 384955912 and 406217369
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
let params = {
'from': '384955912',
'to': '406217369'
};
let query = Object.keys(params)
.map(k => k + '=' + encodeURIComponent(params[k]))
.join('&');
url = url + '?' + query;
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
edittitle
required | path |
Wiki page title |
type
required | path |
Type of count, one of:
|
from
optional | query |
For edits and editors types only
Restricts the count to between two revisions, specified by revision ID. The |
to
optional | query |
Responses
edit200 | Success |
---|---|
400 | Invalid parameter or combination of parameters |
404 | Title or revision not found |
500 | Minor edit count exceeds 2000 |
Response schema
editcount
required | integer |
The value of the data point up to the type's limit. If the value exceeds the limit, the API returns the limit as the value of count and sets the limit property to true.
|
limit
required | boolean |
Returns true if the data point exceeds the type's limit. |
Get revision
editPath | revision/{id}/bare
|
Method | GET
|
---|---|---|---|
Content type | application/json
|
Returns | Revision |
Returns details for an individual revision.
Examples
editcurl
edit# Get information about revision 764138197
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare"
Python
edit# Get information about revision 764138197
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get information about revision 764138197
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get information about revision 764138197
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/bare";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editid
required | path | string |
Revision ID |
Responses
edit200 | Success: Revision found. Returns a revision. |
---|---|
404 | Revision not found |
Get revision source
editPath | revision/{id}
|
Method | GET
|
---|---|---|---|
Content type | application/json
|
Returns | Revision |
Returns details for an individual revision.
Examples
editcurl
edit# Get the wikitext of revision 764138197
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197"
Python
edit# Get the wikitext of revision 764138197
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get the wikitext of revision 764138197
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get the wikitext of revision 764138197
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editid
required | path | string |
Revision ID |
Responses
edit200 | Success: Revision found. Returns a revision. |
---|---|
404 | Revision not found |
Get revision HTML
editPath | revision/{id}/html
|
Method | GET
|
---|---|---|---|
Content type | text/HTML
|
Returns | Revision |
Returns HTML for an individual revision.
Examples
editcurl
edit# Get HTML of revision 764138197
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html"
Python
edit# Get HTML of revision 764138197
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get HTML of revision 764138197
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get HTML of revision 764138197
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/html";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editid
required | path | string |
Revision ID |
Responses
edit200 | Success: Revision found. Returns the revision content as HTML. |
---|---|
404 | Revision not found |
Get revision information with HTML
editPath | revision/{id}/with_html
|
Method | GET
|
---|---|---|---|
Content type | application/json
|
Returns | Revision |
Returns HTML and meta-data for an individual revision.
Examples
editcurl
edit# Get information about revision 764138197 along with rendered HTML
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html"
Python
edit# Get information about revision 764138197 along with rendered HTML
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Get information about revision 764138197 along with rendered HTML
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Get information about revision 764138197 along with rendered HTML
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/revision/764138197/with_html";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editid
required | path | string |
Revision ID |
Responses
edit200 | Revision found. Returns a revision. |
---|---|
404 | Revision not found |
Compare revisions
editRoute | revision/{from}/compare/{to}
|
Content type | application/json
|
---|---|---|---|
Methods | GET
|
Returns | Wikidiff2 JSON diff format |
Returns data that lets you display a line-by-line comparison of two revisions. (See an example.) Only text-based wiki pages can be compared.
Install Wikidiff2 1.9.0 or later.
Examples
editcurl
edit# Compare revision 847170467 to 851733941
$ curl "https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941"
Python
edit# Compare revision 847170467 to 851733941
import requests
url = 'https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941'
headers = {
'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
edit<?php
/*
Compare revision 847170467 to 851733941
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
JavaScript
edit/*
Compare revision 847170467 to 851733941
*/
async function doFetch() {
let url = "https://en.wikipedia.org/w/rest.php/v1/revision/847170467/compare/851733941";
let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
const rsp = await fetch(url, headers);
const data = await rsp.json();
return data;
}
async function fetchAsync()
{
try {
let result = await doFetch();
console.log(result);
} catch( err ) {
console.error( err.message );
}
}
fetchAsync();
Parameters
editfrom
required | path |
Revision identifier to use as the base for comparison |
to
required | path |
Revision identifier to compare to the base |
Responses
edit200 | Success: Revisions found |
---|---|
400 | Revision IDs are for different pages or for pages that can't be compared |
400 | Invalid content type |
403 | Revision not publicly accessible |
404 | Revision not found |
500 | Wikidiff2 extension 1.9.0 or later not installed |
Response schema
editfrom
required | object |
Information about the base revision used in the comparison |
to
required | object |
Information about the revision being compared to the base revision |
from.id
|
Revision identifier |
from.slot_role
|
Area of the page being compared, usually main
|
from.sections
|
Array of objects representing section headings, including:
|
diff
required | array of objects |
Each object in the diff array represents a line in a visual, line-by-line comparison between the two revisions.
|
diff.type
required | integer |
The type of change represented by the diff object, either:
|
diff.lineNumber
optional | integer |
The line number of the change based on the to revision.
|
diff.text
required | string |
The text of the line, including content from both revisions. For a line containing text that differs between the two revisions, you can use highlightRanges to visually indicate added and removed text. For a line containing a new line, the API returns the text as "" (empty string).
|
diff.highlightRanges
optional | array of objects |
An array of objects that indicate where and in what style text should be highlighted to visually represent changes.
Each object includes:
|
diff.moveInfo
optional | object |
Visual indicators to use when a paragraph's location differs between the two revisions. moveInfo objects occur in pairs within the diff.
|
diff.offset
required | object |
The location of the line in bytes from the beginning of the page, including:
|