The main module includes parameters that can be used for any API request.
API documentation
The following documentation is the output of Special:ApiHelp/main, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org).
Status: 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 the mediawiki-api-announce mailing list for notice of updates.
Erroneous requests: 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 API: Errors and warnings.
Acquire a temporary user username and stash it in the current session, if temp account creation is enabled and the current user is logged out. If a name has already been stashed, returns the same name.
Internal. Used by browsers to report violations of the Content Security Policy. This module should never be used, except when used automatically by a CSP compliant web browser.
Maximum lag can be used when MediaWiki is installed on a database replicated cluster. To save actions causing any more site replication lag, this parameter can make the client wait until the replication lag is less than the specified value. In case of excessive lag, error code maxlag is returned with a message like Waiting for $host: $lag seconds lagged. See Manual: Maxlag parameter for more information.
Type: integer
smaxage
Set the s-maxage HTTP cache control header to this many seconds. Errors are never cached.
Type: integer
The value must be no less than 0.
Default: 0
maxage
Set the max-age HTTP cache control header to this many seconds. Errors are never cached.
Type: integer
The value must be no less than 0.
Default: 0
assert
Verify that the user is logged in (including possibly as a temporary user) if set to user, not logged in if set to anon, or has the bot user right if bot.
One of the following values: anon, bot, user
assertuser
Verify the current user is the named user.
Type: user, by any of username and Temporary user
requestid
Any value given here will be included in the response. May be used to distinguish requests.
servedby
Include the hostname that served the request in the results.
When accessing the API using a cross-domain AJAX request (CORS), set this to the originating domain. This must be included in any pre-flight request, and therefore must be part of the request URI (not the POST body).
For authenticated requests, this must match one of the origins in the Origin header exactly, so it has to be set to something like https://en.wikipedia.org or https://meta.wikimedia.org. If this parameter does not match the Origin header, a 403 response will be returned. If this parameter matches the Origin header and the origin is allowed, the Access-Control-Allow-Origin and Access-Control-Allow-Credentials headers will be set.
For non-authenticated requests, specify the value *. This will cause the Access-Control-Allow-Origin header to be set, but Access-Control-Allow-Credentials will be false and all user-specific data will be restricted.
uselang
Language to use for message translations. action=query&meta=siteinfo&siprop=languages returns a list of language codes. You can specify user to use the current user's language preference or content to use this wiki's content language.
Default: user
variant
Variant of the language. Only works if the base language supports variant conversion.
errorformat
Format to use for warning and error text output
plaintext
Wikitext with HTML tags removed and entities replaced.
wikitext
Unparsed wikitext.
html
HTML
raw
Message key and parameters.
none
No text output, only the error codes.
bc
Format used prior to MediaWiki 1.29. errorlang and errorsuselocal are ignored.
One of the following values: bc, html, none, plaintext, raw, wikitext
Default: bc
errorlang
Language to use for warnings and errors. action=query&meta=siteinfo&siprop=languages returns a list of language codes. Specify content to use this wiki's content language or uselang to use the same value as the uselang parameter.
Default: uselang
errorsuselocal
If given, error texts will use locally-customized messages from the MediaWiki namespace.
When accessing the API using a cross-domain AJAX request (CORS), use this to authenticate as the current SUL user. Use action=centralauthtoken on this wiki to retrieve the token, before making the CORS request. Each token may only be used once, and expires after 10 seconds. This should be included in any pre-flight request, and therefore should be included in the request URI (not the POST body).
...
</head><bodyclass="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"><divclass="mw-body"role="main"><h1class="firstHeading">MediaWiki API help</h1><divclass="mw-body-content"><divid="mw-content-text"><p>This is an auto-generated MediaWiki API documentation page.
</p><p>Documentation and examples: <aclass="external free"href="https://www.mediawiki.org/wiki/API">https://www.mediawiki.org/wiki/API</a></p><h2class="apihelp-header"id="main">Main module</h2><divclass="apihelp-block apihelp-flags"><ul><li><spanclass="apihelp-source">Source: <spandir="ltr"lang="en">MediaWiki</span></span></li><li><spanclass="apihelp-license">License: <ahref="/wiki/Special:Version/License/MediaWiki"title="Special:Version/License/MediaWiki"><spandir="ltr"lang="en">GPL-2.0-or-later</span></a></span></li></ul></div><divclass="hlist plainlinks api-main-links"><ul><li><ahref="https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page"class="extiw"title="mw:Special:MyLanguage/API:Main page">Documentation</a></li><li><ahref="https://www.mediawiki.org/wiki/Special:MyLanguage/API:FAQ"class="extiw"title="mw:Special:MyLanguage/API:FAQ">FAQ</a></li><li><aclass="external text"href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-api">Mailing list</a></li><li><aclass="external text"href="https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce">API Announcements</a></li><li><aclass="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 <aclass="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 <ahref="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"""importrequestsS=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*/varurl="https://en.wikipedia.org/w/api.php";varparams={action:"help",format:"json"};url=url+"?origin=*";Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];});fetch(url).then(function(response){returnresponse.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*/varparams={action:'help',format:'json'},api=newmw.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-Action HTTP 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 bot right, so the action could not be completed.
assertnameduserfailed
You are no longer logged in as "assertUser", so the action could not be completed.