| This page is part of theMediaWiki Action API documentation. |
| MediaWiki Action API |
|---|
| Basics |
| Authentication |
| Accounts and Users |
| Page Operations |
|
| Search |
| Developer Utilities |
| Tutorials |
| v · d · e |
In this tutorial, you will learn about theMediaWiki Action API, how to use it, request format, a simple query, and examples of projects using Action API.
TheMediaWiki Action API is aRESTfulweb service that allows users to perform certain wiki-actions like page creation, authentication, parsing, searching, etc.API:Main page is a good starting point for understanding the API.
Your program sends requests to the API to get access to wiki features.For example, log in to a wiki, create and edit a page, search for a title, search for content text, or parse content.The Action API is available for third-party developers, Wikimedia extension developers, and wiki site administrators.
On the right sidebar of this page, there are many features that are supported by the API, grouped by category.Before sending requests to a wiki server, first read through the overview pages such asdata formats,errors and warnings, and theAction API FAQ.
You can request for data from client side to the server overHTTP and get the response back in a standard format (typicallyJSON).A request consists of an endpoint and a set of parameters.There are two types of request that can be made:GET andPOST.For a GET request, a parameter would contain a query string in the URL.For a POST request, format the parameters inJSON format.

All Wikimedia Wikis have endpoints in this formathttp://example.org/w/api.php.To operate on the MediaWiki main site or English Wikipedia, use the related endpoint.For example, the English Wikipedia is athttps://en.wikipedia.org/w/api.php.For testing new accounts or test edits to pages, use the test wiki endpointhttps://test.wikipedia.org/w/api.php.
In the query string in the URL, add theaction parameter.It tells the API which action to perform.The most popular action isquery (the URL would containaction=query), which allows fetching data from a wiki.Following theaction parameter, add another parameter to indicate which one of the three query module types you want to perform:
prop - get properties of pages list - get list of pages matching a certain criterionmeta - get meta information about the wiki and userFinally, include theformat parameter, which tells the API in which format to get the results.The recommended format is JSON.The API hassupported other output formats in the past, but they are not generally recommended.
Let’s take an example of a simple query to understand what a typical GET request and response would look like in the context of the Action API.
Let's search for a title in a wiki. We will use thesearch module documented onAPI:Search.
To search for page titles or content matchingCraig Noone, the URL for the HTTP GET request would be:
Explanation of each part of the URL:
http://en.wikipedia.org/w/api.php is the main endpoint. In this case it is English Wikipedia.action=query means fetch data from wiki.list=search means get list of pages matching a criteria.srsearch=Craig%20Noone indicates the page title or content to search for. The%20 indicates a space character in a URL.format=json indicates JSON output, which is the recommended output format.The response is a JSON format document with a list of pages titles that matchCraig Noone:
{"batchcomplete":"","continue":{"sroffset":10,"continue":"-||"},"query":{"searchinfo":{"totalhits":210},"search":[{"ns":0,"title":"Craig Noone","pageid":18846922,"size":22548,"wordcount":1771,"snippet":"<span class=\"searchmatch\">Craig</span> Stephen <span class=\"searchmatch\">Noone</span> (born 17 November 1987) is an English professional footballer who plays as a winger for Bolton Wanderers. Born in Kirkby, he has also","timestamp":"2018-11-02T22:25:45Z"},{"ns":0,"title":"Noone","pageid":32906333,"size":553,"wordcount":64,"snippet":"<span class=\"searchmatch\">Noone</span> is a surname that may refer to: <span class=\"searchmatch\">Craig</span> <span class=\"searchmatch\">Noone</span> (born 1987), English football midfielder Jimmie <span class=\"searchmatch\">Noone</span> (1895–1944), American jazz clarinetist Kathleen","timestamp":"2015-08-16T05:16:17Z"}...]}}
Some example of projects in Wikimedia that use Action API: