GET /core/v1/{project}/{language}/search/page?q=search terms

Searches wiki pages for the given search terms, and returns matching pages.

Examples

curl

# Search English Wikipedia for 10 articles about Earth
$ curl https://api.wikimedia.org/core/v1/wikipedia/en/search/page?q=earth&limit=10

Python

# Python 3
# Search English Wikipedia for 10 articles about Earth

import requests

url = 'https://api.wikimedia.org/core/v1/wikipedia/en/search/page'
search_query = 'earth'
number_of_results = 10
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 10 articles about Earth

$params = array('q' => 'earth', 'limit' => '10');
$url = 'https://api.wikimedia.org/core/v1/wikipedia/en/search/page?' . 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 10 articles about Earth

let url = 'https://api.wikimedia.org/core/v1/wikipedia/en/search/page?q=earth&limit=10';
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.
Note: The language parameter is prohibited for commons and other multilingual projects.
q

required query

Search terms
limit

optional query

Maximum number of search results to return, between 1 and 100. Default: 50

Responses

200 Success: Results found. Returns a pages array containing search results.
Example
{
  "pages": [
    {
      "id": 9228,
      "key": "Earth",
      "title": "Earth",
      "excerpt": "evidence, <span class=\"searchmatch\">Earth</span> formed over 4.5 billion years ago. <span class=\"searchmatch\">Earth</span>'s gravity interacts with other objects in space, especially the Sun and the Moon, which is <span class=\"searchmatch\">Earth</span>'s only",
      "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": 2126501,
      "key": "Google_Earth",
      "title": "Google Earth",
      "excerpt": "Google <span class=\"searchmatch\">Earth</span> is a computer program that renders a 3D representation of <span class=\"searchmatch\">Earth</span> based primarily on satellite imagery. The program maps the <span class=\"searchmatch\">Earth</span> by superimposing",
      "description": "virtual map program developed by Google",
      "thumbnail": {
        "mimetype": "image/svg+xml",
        "size": 11912,
        "width": 200,
        "height": 200,
        "duration": null,
        "url": "//upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Google_Earth_icon.svg/200px-Google_Earth_icon.svg.png"
      }
    }
  ]
}
200 Success: No results found. Returns an empty pages array.
Example
{
  "pages": []
}
400 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 Invalid limit requested. Set limit parameter to between 1 and 100.
Example
{
  "error": "parameter-validation-failed",
  "name": "limit",
  "value": "0",
  "failureCode": "outofrange",
  "failureData": {
    "min": 1,
    "curmax": 100,
    "max": 100,
    "highmax": 100
  },
  "messageTranslations": {
    "en": "The value \"0\" for parameter \"limit\" must be between 1 and 100."
  },
  "httpCode": 400,
  "httpReason": "Bad Request"
}