|  | This page is part of the MediaWiki Action API documentation. | 
The main module includes parameters that can be used for any API request.
API documentation
| 
 Special:ApiHelp/main | 
Example
GET request
Get help for the main module.
Response
...
</head>
<body class="mediawiki ltr sitedir-ltr mw-hide-empty-elt ns--1 ns-special mw-special-ApiHelp page-Special_ApiHelp rootpage-Special_ApiHelp skin-apioutput action-view">
		<div class="mw-body" role="main">
			<h1 class="firstHeading">MediaWiki API help</h1>
			<div class="mw-body-content">
				<div id="mw-content-text"><p>This is an auto-generated MediaWiki API documentation page.
</p><p>Documentation and examples: <a class="external free" href="https://www.mediawiki.org/wiki/API">https://www.mediawiki.org/wiki/API</a>
</p><h2 class="apihelp-header" id="main">Main module</h2>
<div class="apihelp-block apihelp-flags"><ul><li><span class="apihelp-source">Source: <span dir="ltr" lang="en">MediaWiki</span></span></li><li><span class="apihelp-license">License: <a href="/wiki/Special:Version/License/MediaWiki" title="Special:Version/License/MediaWiki"><span dir="ltr" lang="en">GPL-2.0-or-later</span></a></span></li></ul></div>
<div class="hlist plainlinks api-main-links">
<ul><li><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page" class="extiw" title="mw:Special:MyLanguage/API:Main page">Documentation</a></li>
<li><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/API:FAQ" class="extiw" title="mw:Special:MyLanguage/API:FAQ">FAQ</a></li>
<li><a class="external text" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-api">Mailing list</a></li>
<li><a class="external text" href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce">API Announcements</a></li>
<li><a class="external text" href="https://phabricator.wikimedia.org/maniphest/query/GebfyV4uCaLd/#R">Bugs & requests</a></li></ul></div>
<p><strong>Status:</strong> The MediaWiki API is a mature and stable interface that is actively supported and improved. While we try to avoid it, we may occasionally need to make breaking changes; subscribe to <a class="external text" href="https://lists.wikimedia.org/pipermail/mediawiki-api-announce/">the mediawiki-api-announce mailing list</a> for notice of updates.
</p><p><strong>Erroneous requests:</strong> When erroneous requests are sent to the API, an HTTP header will be sent with the key "MediaWiki-API-Error" and then both the value of the header and the error code sent back will be set to the same value. For more information see <a href="https://www.mediawiki.org/wiki/Special:MyLanguage/API:Errors_and_warnings" class="extiw" title="mw:Special:MyLanguage/API:Errors and warnings">API: Errors and warnings</a>.
</p>
...
Sample code
Python
#!/usr/bin/python3
"""
    main_module.py
    MediaWiki API Demos
    Demo of `Main module` module: Get help for the main module.
    MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
    "action": "help",
    "format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
    main_module.php
    MediaWiki API Demos
    Demo of `Main module` module: Get help for the main module.
    MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "help",
    "format" => "json"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
var_dump( $result );
JavaScript
/*
    main_module.js
    MediaWiki API Demos
    Demo of `Main module` module: Get help for the main module.
    MIT License
*/
var url = "https://en.wikipedia.org/w/api.php"; 
var params = {
    action: "help",
    format: "json"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
    .then(function(response){return response.json();})
    .then(function(response) {console.log(response);})
    .catch(function(error){console.log(error);});
MediaWiki JS
/*
	main_module.js
	MediaWiki API Demos
	Demo of `Main module` module: Get help for the main module.
	MIT License
*/
var params = {
		action: 'help',
		format: 'json'
	},
	api = new mw.Api();
api.get( params ).done( function ( data ) {
	console.log( data );
} );
Possible errors
| Code | Info | 
|---|---|
| unknownaction | The action specified, action, is not recognized. | 
| unknownformat | Unrecognized format "format". | 
| missingparam | The $1 parameter must be set. | 
| maxlag | Waiting for host: lag seconds lagged. | 
| maxlag | Waiting for a database server: lag seconds lagged. | 
| readapidenied | You need read permission to use this module. | 
| noapiwrite | Editing of this wiki through the API is disabled. | 
| writeapidenied | You're not allowed to edit this wiki through the API. | 
| promised-nonwrite-api | The Promise-Non-Write-API-ActionHTTP header cannot be sent to write-mode API modules. | 
| readonly_lag | The database has been automatically locked while the replica database servers catch up to the primary | 
| assertanonfailed | You are no longer logged out, so the action could not be completed. | 
| assertuserfailed | You are no longer logged in, so the action could not be completed. | 
| assertbotfailed | You do not have the botright, so the action could not be completed. | 
| assertnameduserfailed | You are no longer logged in as "assertUser", so the action could not be completed. | 
| invalidmethod | Invalid HTTP method. Consider using GET or POST. | 
| mustbeposted | The $1 module requires a POST request. | 
Parameter history
- v1.17:  Introduced servedby
- v1.14:  Introduced requestid
See also
- Manual:Parameters to index.php - A partial list of the parameters to index.php, the main script of the MediaWiki software.
    This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.
