Core REST API/Reference/Pages/Get page source
GET | /core/v1/{project}/{language}/page/{title}
|
---|
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
curl
# Get the wikitext version of the Earth article on English Wikipedia
$ curl https://api.wikimedia.org/core/v1/wikipedia/en/page/Earth
Python
# Python 3
# Get the wikitext version of the Earth article on English Wikipedia
import requests
page = 'Earth'
url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/' + page
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
<?php
// Get the wikitext version of the Earth article on English Wikipedia
$url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Earth';
$authorization = 'Authorization: Bearer YOUR_ACCESS_TOKEN';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>
JavaScript
// Get the wikitext version of the Earth article on English Wikipedia
let url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Earth';
let response = await fetch( url,
{
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Api-User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
}
);
response.json()
.then(console.log).catch(console.error);
Parameters
project
required path |
Project name. For example: wikipedia (encyclopedia articles), commons (images, audio, and video), wiktionary (dictionary entries). List all projects.
|
language
required path |
Language code. For example: ar (Arabic), en (English), es (Spanish). List supported languages.
|
title
required path |
Wiki page title |
Responses
200 | Success: Page found. Returns a page with the source property.
Example
{
"id": 9228,
"key": "Earth",
"title": "Earth",
"latest": {
"id": 989181479,
"timestamp": "2020-11-17T14:42:31Z"
},
"content_model": "wikitext",
"license": {
"url": "//creativecommons.org/licenses/by-sa/3.0/",
"title": "Creative Commons Attribution-Share Alike 3.0"
},
"source": "{{Short description|Third planet from the Sun in the Solar System}}\n{{About|the planet|its human aspects|World|other uses|Earth (disambiguation)|and|Planet Earth (disambiguation)}}\n{{pp-semi|small=yes}}\n{{Use American English|date=August 2019}}\n{{Use dmy dates|date=January 2020}}\n{{Featured article}}\n\n{{Infobox planet..}}"
}
|
---|---|
404 | Error: Content doesn't exist or cannot be loaded
Example
{
"messageTranslations": {
"en": "The specified title does not exist"
},
"httpCode": 404,
"httpReason": "Not Found"
}
|