Core REST API/Reference/Search/Search titles
GET | /core/v1/{project}/{language}/search/title?q=search terms
|
---|
Searches wiki page titles, and returns pages with titles that begin with the provided search terms. You can use this endpoint as an autocomplete search that automatically suggests relevant pages by title.
Examples
curl
# Search English Wikipedia for 5 pages with titles that start with "earth"
$ curl https://api.wikimedia.org/core/v1/wikipedia/en/search/title?q=earth&limit=5
Python
# Python 3
# Search English Wikipedia for 5 pages with titles that start with "earth"
import requests
url = 'https://api.wikimedia.org/core/v1/wikipedia/en/search/title'
search_query = 'earth'
number_of_results = 5
parameters = {'q': search_query, 'limit': number_of_results}
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
response = requests.get(url, headers=headers, params=parameters)
data = response.json()
print(data)
PHP
<?php
// Search English Wikipedia for 5 pages with titles that start with "earth"
$params = array('q' => 'earth', 'limit' => '5');
$url = 'https://api.wikimedia.org/core/v1/wikipedia/en/search/title?' . http_build_query($params);
$token = 'YOUR_ACCESS_TOKEN';
$authorization = 'Authorization: Bearer ' . $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
// Search English Wikipedia for 5 pages with titles that start with "earth"
let url = 'https://api.wikimedia.org/core/v1/wikipedia/en/search/title?q=earth&limit=5';
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.
|
q
required query |
Search terms |
limit
optional query |
Maximum number of search results to return, between 1 and 100. Default: 50 |
Responses
200 | Success: Returns a pages array containing search results.
Example
{
"pages": [
{
"id": 9228,
"key": "Earth",
"title": "Earth",
"excerpt": "Earth",
"matched_title": null,
"description": "Third planet from the Sun in the Solar System",
"thumbnail": {
"mimetype": "image/jpeg",
"size": null,
"width": 200,
"height": 200,
"duration": null,
"url": "//upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/200px-The_Earth_seen_from_Apollo_17.jpg"
}
},
{
"id": 10106,
"key": "Earthquake",
"title": "Earthquake",
"excerpt": "Earthquake",
"matched_title": null,
"description": "Shaking of the surface of the earth caused by a sudden release of energy in the crust",
"thumbnail": {
"mimetype": "image/png",
"size": null,
"width": 200,
"height": 125,
"duration": null,
"url": "//upload.wikimedia.org/wikipedia/commons/thumb/d/db/Quake_epicenters_1963-98.png/200px-Quake_epicenters_1963-98.png"
}
}
]
}
|
---|---|
400 | Error: Query parameter not set. Add q parameter.
Example
{
"error": "parameter-validation-failed",
"name": "q",
"value": null,
"failureCode": "missingparam",
"failureData": null,
"messageTranslations": {
"en": "The \"q\" parameter must be set."
},
"httpCode": 400,
"httpReason": "Bad Request"
}
|
400 | Error: Invalid limit requested. Set limit parameter to between 1 and 100.
Example
{
"error": "parameter-validation-failed",
"name": "limit",
"value": "200",
"failureCode": "outofrange",
"failureData": {
"min": 1,
"curmax": 100,
"max": 100,
"highmax": 100
},
"messageTranslations": {
"en": "The value \"200\" for parameter \"limit\" must be between 1 and 100."
},
"httpCode": 400,
"httpReason": "Bad Request"
}
|