API:Main page
<translate> This page is part of the [[<tvar name="main">Special:MyLanguage/API:Main_page</tvar>|MediaWiki Action API]] documentation.</translate> |
This page provides an overview of the MediaWiki Action API, represented by the api.php endpoint.
This page is intended for technical contributors and software developers who wish to understand and use the MediaWiki Action API.
Quick Start
Get the contents of an article on English Wikipedia in HTML:
Endpoint
All Wikimedia wikis have endpoints that follow this pattern: https://www.example.org/w/api.php
| API Endpoint | Wiki |
|---|---|
https://www.mediawiki.org/w/api.php
|
MediaWiki API |
https://meta.wikimedia.org/w/api.php
|
Meta-Wiki API |
https://en.wikipedia.org/w/api.php
|
English Wikipedia API |
https://nl.wikipedia.org/w/api.php
|
Dutch Wikipedia API |
https://commons.wikimedia.org/w/api.php
|
Wikimedia Commons API |
https://test.wikipedia.org/w/api.php
|
Test Wiki API |
To see the endpoint URL on a particular wiki, see section "Entry point URLs" on the Special:Version page.
Introduction
The MediaWiki Action API is a web service that allows access to some wiki features like authentication, page operations, and search. It can provide meta information about the wiki and the logged-in user.
Uses for the MediaWiki Action API
- Monitor a MediaWiki installation
- Create a bot to maintain a MediaWiki installation
- Log in to a wiki, access data, and post changes by making HTTP requests to the web service
Getting started with MediaWiki Action API
Before you start using the MediaWiki Action API, you should review the following pages:
- API etiquette and usage guidelines
- Frequently asked questions
- Input and output formats
- Errors and warnings
- Any policies that apply to the wiki you want to access, such as Wikimedia Foundation wikis' terms of use and trademark policy. These terms apply to you when you access or edit using the API, just as they do when you use your web browser.
API documentation
<translate> The following documentation is the output of <tvar name=special>Special: |
Main module
- Source: MediaWiki
- License: GPL-2.0-or-later
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.
Testing: For ease of testing API requests, see Special:ApiSandbox.
- action
Which action to perform.
- acquiretempusername
- 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.
- aggregategroups
- Manage aggregate message groups.
- block
- Block a user.
- changeauthenticationdata
- Change authentication data for the current user.
- changecontentmodel
- Change the content model of a page
- checktoken
- Check the validity of a token from action=query&meta=tokens.
- clearhasmsg
- Clears the
hasmsgflag for the current user. - clientlogin
- Log in to the wiki using the interactive flow.
- compare
- Get the difference between two pages.
- createaccount
- Create a new user account.
- delete
- Delete a page.
- edit
- Create and edit pages.
- emailuser
- Email a user.
- expandtemplates
- Expands all templates within wikitext.
- feedcontributions
- Returns a user's contributions feed.
- feedrecentchanges
- Returns a recent changes feed.
- feedwatchlist
- Returns a watchlist feed.
- filerevert
- Revert a file to an old version.
- groupreview
- Set message group workflow states.
- help
- Display help for the specified modules.
- imagerotate
- Rotate one or more images.
- import
- Import a page from another wiki, or from an XML file.
- jsonconfig
- Allows direct access to JsonConfig subsystem.
- languagesearch
- Search for language names in any script.
- linkaccount
- Link an account from a third-party provider to the current user.
- login
- Log in and get authentication cookies.
- logout
- Log out and clear session data.
- managetags
- Perform management tasks relating to change tags.
- mergehistory
- Merge page histories.
- move
- Move a page.
- opensearch
- Search the wiki using the OpenSearch protocol.
- options
- Change preferences of the current user.
- paraminfo
- Obtain information about API modules.
- parse
- Parses content and returns parser output.
- patrol
- Patrol a page or revision.
- protect
- Change the protection level of a page.
- purge
- Purge the cache for the given titles.
- query
- Fetch data from and about MediaWiki.
- removeauthenticationdata
- Remove authentication data for the current user.
- resetpassword
- Send a password reset email to a user.
- revisiondelete
- Delete and undelete revisions.
- rollback
- Undo the last edit to the page.
- rsd
- Export an RSD (Really Simple Discovery) schema.
- searchtranslations
- Search translations.
- setnotificationtimestamp
- Update the notification timestamp for watched pages.
- setpagelanguage
- Change the language of a page.
- tag
- Add or remove change tags from individual revisions or log entries.
- translationaids
- Query all translations aids.
- translationreview
- Mark translations reviewed.
- translationstats
- Fetch translation statistics
- ttmserver
- Query suggestions from translation memories.
- unblock
- Unblock a user.
- undelete
- Undelete revisions of a deleted page.
- unlinkaccount
- Remove a linked third-party account from the current user.
- upload
- Upload a file, or get the status of pending uploads.
- userrights
- Change a user's group membership.
- validatepassword
- Validate a password against the wiki's password policies.
- watch
- Add or remove pages from the current user's watchlist.
- wbavailablebadges
- Queries available badge items.
- wbcreateclaim
- Creates Wikibase claims.
- wbcreateredirect
- Creates Entity redirects.
- wbeditentity
- Creates a single new Wikibase entity and modifies it with serialised information.
- wbformatentities
- Formats entity IDs to HTML.
- wbformatvalue
- Formats DataValues.
- wbgetclaims
- Gets Wikibase claims.
- wbgetentities
- Gets the data for multiple Wikibase entities.
- wblinktitles
- Associates two pages on two different wikis with a Wikibase item.
- wbmergeitems
- Merges multiple items.
- wbparsevalue
- Parses values using a
ValueParser. - wbremoveclaims
- Removes Wikibase claims.
- wbremovequalifiers
- Removes a qualifier from a claim.
- wbremovereferences
- Removes one or more references of the same statement.
- wbsearchentities
- Searches for entities using labels and aliases.
- wbsetaliases
- Sets the aliases for a Wikibase entity.
- wbsetclaim
- Creates or updates an entire Statement or Claim.
- wbsetclaimvalue
- Sets the value of a Wikibase claim.
- wbsetdescription
- Sets a description for a single Wikibase entity.
- wbsetlabel
- Sets a label for a single Wikibase entity.
- wbsetqualifier
- Creates a qualifier or sets the value of an existing one.
- wbsetreference
- Creates a reference or sets the value of an existing one.
- wbsetsitelink
- Associates a page on a wiki with a Wikibase item or removes an already made such association.
- cspreport
- 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.
- editcheckreferenceurl
- Internal. Check the status of a URL for use as a reference.
- managegroupsynchronizationcache
- Internal. Manage group synchronization cache.
- managemessagegroups
- Internal. Add a message as a rename of an existing message or a new message in the group during imports
- messagegroupsubscription
- Internal. Message group subscription related operations
- scribunto-console
- Internal. Internal module for servicing XHR requests from the Scribunto console.
- stashedit
- Internal. Prepare an edit in shared cache.
- translationcheck
- Internal. Validate translations.
- translationentitysearch
- Internal. Search for message groups and messages
- ulslocalization
- Internal. Get the localization of ULS in the given language.
- ulssetlang
- Internal. Update user's preferred interface language.
- visualeditor
- Internal. Returns HTML5 for a page from the Parsoid service.
- visualeditoredit
- Internal. Save an HTML5 page to MediaWiki (converted to wikitext via the Parsoid service).
- One of the following values: acquiretempusername, aggregategroups, block, changeauthenticationdata, changecontentmodel, checktoken, clearhasmsg, clientlogin, compare, createaccount, delete, edit, emailuser, expandtemplates, feedcontributions, feedrecentchanges, feedwatchlist, filerevert, groupreview, help, imagerotate, import, jsonconfig, languagesearch, linkaccount, login, logout, managetags, mergehistory, move, opensearch, options, paraminfo, parse, patrol, protect, purge, query, removeauthenticationdata, resetpassword, revisiondelete, rollback, rsd, searchtranslations, setnotificationtimestamp, setpagelanguage, tag, translationaids, translationreview, translationstats, ttmserver, unblock, undelete, unlinkaccount, upload, userrights, validatepassword, watch, wbavailablebadges, wbcreateclaim, wbcreateredirect, wbeditentity, wbformatentities, wbformatvalue, wbgetclaims, wbgetentities, wblinktitles, wbmergeitems, wbparsevalue, wbremoveclaims, wbremovequalifiers, wbremovereferences, wbsearchentities, wbsetaliases, wbsetclaim, wbsetclaimvalue, wbsetdescription, wbsetlabel, wbsetqualifier, wbsetreference, wbsetsitelink, cspreport, editcheckreferenceurl, managegroupsynchronizationcache, managemessagegroups, messagegroupsubscription, scribunto-console, stashedit, translationcheck, translationentitysearch, ulslocalization, ulssetlang, visualeditor, visualeditoredit
- Default: help
- format
The format of the output.
- json
- Output data in JSON format.
- jsonfm
- Output data in JSON format (pretty-print in HTML).
- none
- Output nothing.
- php
- Output data in serialized PHP format.
- phpfm
- Output data in serialized PHP format (pretty-print in HTML).
- rawfm
- Output data, including debugging elements, in JSON format (pretty-print in HTML).
- xml
- Output data in XML format.
- xmlfm
- Output data in XML format (pretty-print in HTML).
- One of the following values: json, jsonfm, none, php, phpfm, rawfm, xml, xmlfm
- Default: jsonfm
- maxlag
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-maxageHTTP 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-ageHTTP 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.
- Type: boolean (details)
- curtimestamp
Include the current timestamp in the result.
- Type: boolean (details)
- responselanginfo
Include the languages used for uselang and errorlang in the result.
- Type: boolean (details)
- origin
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
Originheader 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 theOriginheader, a 403 response will be returned. If this parameter matches theOriginheader and the origin is allowed, theAccess-Control-Allow-OriginandAccess-Control-Allow-Credentialsheaders will be set.For non-authenticated requests, specify the value *. This will cause the
Access-Control-Allow-Originheader to be set, butAccess-Control-Allow-Credentialswill befalseand 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.
- Type: boolean (details)
- Help for the main module.
- api.php?action=help [open in sandbox]
- All help in one page.
- api.php?action=help&recursivesubmodules=1 [open in sandbox]
Other APIs
If you do not find what you are looking for in this API documentation, there are many other APIs related to Wikimedia projects.
For the REST API included with MediaWiki 1.35 and later, see API:REST API.
| <translate> API</translate> | <translate> Availability</translate> | <translate> URL base</translate> | <translate> Example</translate> |
|---|---|---|---|
| <translate> Included with MediaWiki</translate>
<translate> Enabled on [[<tvar name=1>m:Special:MyLanguage/Wikimedia projects</tvar>|Wikimedia projects]]</translate> |
/api.php | https://<translate nowrap> en.wikipedia.org</translate>/w/api.php?action=query&prop=info&titles=<translate nowrap> Earth</translate> | |
| <translate> Included with MediaWiki 1.35+</translate>
<translate> Enabled on [[<tvar name=1>m:Special:MyLanguage/Wikimedia projects</tvar>|Wikimedia projects]]</translate> |
/rest.php | https://<translate nowrap> en.wikipedia.org</translate>/w/rest.php/v1/page/<translate nowrap> Earth</translate> | |
| <translate> Not included with MediaWiki</translate>
<translate> Available for [[<tvar name=1>m:Special:MyLanguage/Wikimedia projects</tvar>|Wikimedia projects]] only</translate> |
/api/rest | https://<translate nowrap> en.wikipedia.org</translate>/api/rest_v1/page/title/<translate nowrap> Earth</translate> | |
Code stewardship
- <translate> Maintained by <tvar name=1>MediaWiki Interfaces Team</tvar>.</translate>
- <translate> Live chat ([[<tvar name=1>Special:MyLanguage/MediaWiki on IRC</tvar>|IRC]]): <tvar name=2><span class="plainlinks" style="font-family: monospace,Courier; white-space: pre-wrap !important; word-wrap: break-word; max-width: 1200px; overflow: auto;" title="<translate nowrap> <tvar name=1>#mediawiki-core</tvar> on Libera.Chat IRC</translate>">#mediawiki-core <translate> connect</translate></tvar></translate>
- <translate> Issue tracker: [<tvar name=url>https://phabricator.wikimedia.org/tag/mediawiki-action-api/</tvar> Phabricator <tvar name=phab>MediaWiki-Action-API</tvar>] ([<tvar name=url2>https://phabricator.wikimedia.org/maniphest/task/edit/form/1/?projects=mediawiki-action-api</tvar> Report an issue])</translate>