API:Main page


 * This is an introductory overview. See the menu bar on the right for more detailed sub-topics.

The MediaWiki web service API (or WebAPI) provides convenient access to wiki features, data and meta-data.

Introduction
Mediawiki API can be used to monitor a MediaWiki installation, or create a bot to automatically maintain one. It provides direct, high-level access to the data contained in MediaWiki databases. Client programs can log in to a wiki, get data, and post changes automatically by making HTTP requests to the web service. Supported clients include bots, thin web-based JavaScript clients such as Navigation popups and LiveRC, end-user applications such as Vandal Fighter, and other web sites (Toolserver's utilities).

On new MediaWiki installations, the web service is enabled by default, but an administrator can disable it.

Basic Aspects
There are 3 main and basic aspects of the mediawiki API i.e Parsing, Querying and Editing.
 * Parsing module allow api calling the parser for preprocessing and rendering. Refer  Parse API for more details and examples.
 * Queryig module allows you to get most of the data stored in a wiki like meta information about the wiki and the logged-in user,properties of pages, including page revisions and content, lists of pages that match certain criteria and also including tokens for editing. Refer  Query API for further details and examples.
 * Editing module allows you to edit Wikipedia pages by logging into the respective user account. Refer Edit API for editing references.

A simple example
This URL tells Simple Wikipedia's web service API to send you the content of the main page:

 http://simple.wikipedia.org/w/api.php?format=json&action=query&titles=Main%20Page&prop=revisions&rvprop=content

Let's pick that URL apart to show how it works.

The endpoint
This is the endpoint. It's like the home page of the Mediawiki web service API. This URL is the base URL for Simple Wikipedia's API, just as  is the base URL for its web site.

If you're writing a program to use English Wikipedia, every URL you construct will begin with http://en.wikipedia.org/w/api.php. If you're using a different MediaWiki installation, you'll need to find its endpoint and use that instead. All Wikimedia wikis have endpoints that follow this pattern:

http://en.wikipedia.org/w/api.php     # English Wikipedia API http://nl.wikipedia.org/w/api.php     # Dutch Wikipedia API http://commons.wikimedia.org/w/api.php # Wikimedia Commons API

Now let's move on to the parameters in the query string of the URL.

The format
This tells the Wikimedia web service API that we want data to be returned in JSON format. You might also want to try  to get an HTML version of the result that is good for debugging. Even though the API supports many different output formats such as WDDX, XML, YAML and native PHP, there are plans to remove all formats except for JSON, so you might not want to use them.

The action
This is the 'action'. The MediaWiki web service API supports over fifty actions, and they're all documented in the [//en.wikipedia.org/w/api.php API reference]. In this case, we're using "query" to tell the API that we want to get some data.

The action=query, action=parse and action=edit are main actions of mediawiki api as mentioned in above section of basic aspects.

Action-specific parameters
The rest of the example URL contains parameters used by the "query" action. Here, we're telling the web service API that we want information about the Wiki page called "Main Page". (The %20 comes from percent-encoding a space.) If you need to work with multiple pages, please consider putting them all in one request to optimize network and server resources:. See the query documentation for details.

This parameter tells the web service API that we are interested in a particular revision of the page. Since we're not specifying any revision information, the API will give us information about the latest revision &mdash; the main page of Wikipedia as it stands right now.

Finally, this parameter tells the web service API that we want the content of the latest revision of the page. If we passed in  instead, we'd get the latest page content and the name of the user who made the most recent revision.

Again, this is just one example. Queries are explained in more detail here, and the API reference lists all the possible actions, all the possible values for, and so on.



An example with JSON and AJAX
 $(document).ready(function{   var req = {        format: 'json',        action: 'parse',        page: 'New York City',        prop: 'text',        section: 0    };    $.ajax({ url: '//simple.wikipedia.org/w/api.php' data: req, cache: true, dataType: 'jsonp', success: function(result) { // Add result's HTML to the top of the $('body').prepend(result.parse.text['*']); // Append full JSON result to output $('#json').text(JSON.stringify(result, '', 2)); }   }); });

Getting started
You can start with Introductory tutorials on | Codecademy Link to tutorials: You can also read the following documents:
 * | Introduction to Wikipedia API
 * | Wikipedia: Query API
 * The FAQ,input and output formats,errors and warnings,terms of use,also read API:Etiquette.

Identifying your client
When you make HTTP requests to the MediaWiki web service API, be sure to specify a  header that properly identifies your client. Don't use the default  provided by your client library, but make up a custom header that identifies your script or service and provides some type of means of contacting you (e.g., an e-mail address).

An example User-Agent string might look like: MyCoolTool/1.1 (http://example.com/MyCoolTool/; MyCoolTool@example.com) BasedOnSuperLib/1.4

On Wikimedia wikis, if you don't supply a  header, or you supply an empty or generic one, your request will fail with an HTTP 403 error (cf. User-Agent policy). Other MediaWiki installations may have similar policies.

If you are calling the API from browser-based JavaScript, you won't be able to influence the  header: the browser will use its own. There is currently no other mechanism for a browser-based client to identify itself.

In PHP, you can identify your user-agent with code such as this:

Or if you use cURL:

Useful links
The menu bar on the right side of this page links to more detailed, task-specific documentation. Here are some links having to do with the API as a whole:
 * The API sandbox available on all Wikimedia wikis makes it easy to try out different actions interactively.
 * [//en.wikipedia.org/w/api.php The API reference] contains automatically-generated descriptions of all actions and parameters.
 * Hook into Wikipedia information using PHP and the MediaWiki API (IBM developerWorks article, 17 May 2011)
 * Hook into Wikipedia using Java and the MediaWiki API (6 April 2012)
 * The API tutorial leads you through hands-on exercises and includes a training video.
 * Mailing list for notifications and questions: API mailing list
 * Low-traffic mailing list for announcements only (all posts to this list are posted to mediawiki-api as well): mediawiki-api-announce
 * View and report API bugs: Bugzilla (When reporting new bugs, don't forget to set Component=API)
 * The current MediaWiki database schema
 * The current MediaWiki database schema

Archived links

 * 2006 API discussion