API:Errors and warnings

From MediaWiki.org
Jump to: navigation, search
Language:Project:Language policy English  • Deutsch • español • français • 日本語 • 한국어
This page is part of the MediaWiki action API documentation.

MediaWiki action API

v · d · e

If something goes wrong in an API request, an error or a warning will be thrown (although the HTTP response will usually still be 200 OK). Warnings are thrown for non-fatal conditions such as invalid parameters, whereas errors are only thrown for fatal conditions.


Warnings are output in the following format:

<?xml version="1.0" encoding="utf-8"?>
    <query>Warning text
Another warning</query>
    <info>A warning from prop=info</info>

As shown in the example, warnings are grouped by the name of the module that caused them. Multiple warnings from the same module are separated by a newline.

Disabled submodules[edit]

Disabled action=query submodules will always throw the following warning:

  • The "modulename" module has been disabled.

Missing module warnings[edit]

If you specify a module in a multi-value list, such as a list, meta, or prop list of query submodules, and the module is not present on a wiki, for example it is implemented by an extension that isn't loaded, then requesting throws the warning "Unrecognized value for parameter ..." and possibly additional warnings for the submodule's parameters. For example for a list query submodule, raremodule, a query such as


  • "Unrecognized value for parameter 'list': raremodule"

See also Missing module errors below

You can check to see if a module is available before invoking it, see [How do I] check if an API module is available? in the FAQ.

Parameter validation warnings[edit]

The MediaWiki API may return the following warnings when validating parameters of any API module. paramname is replaced by the name of the parameter.

  • Too many values supplied for parameter 'paramname': the limit is limit
  • Unrecognized value for parameter 'paramname': value
  • Unrecognized values for parameter 'paramname': value1, value2, value3


The MediaWiki API returns errors in the following structure (shown for format=xml):

<error code="codestring" info="info text" />

Where codestring is a short error code (which need not be unique to the error) and info text is a more elaborate description of the error (which should be unique). Also, it returns the error code in a MediaWiki-API-Error HTTP header. For an example error response or to test your client's error handling, visit https://en.wikipedia.org/w/api.php?action=blah

Note that when viewing errors in pretty-print formats, the API help will be returned inside the <error> element. To save bandwidth, this doesn't happen for non-pretty-print formats; if you specifically want the help text in a non-pretty-print format, use action=help.

Error messages in the documentation[edit]

Error messages are documented as follows:

Code Info
apparams prlevel may not be used without prtype

Which corresponds to:

<error code="apparams" info="prlevel may not be used without prtype" />

for XML or:

"error": {
    "code": "maxlagapparams",
    "info": "prlevel may not be used without prtype",
    "*": "See https://www.mediawiki.org/w/api.php for API usage."

for json. When using a different formatversion than 1 with json, the "*" field will be named "docref" instead.

Disabled modules[edit]

Disabled action= modules will always fail with the following error:

Code Info
moduledisabled The modulename module has been disabled.

Missing module errors[edit]

If you specify a module as the single value of a parameter such as action and it is not present on a wiki, for example it is implemented by an extension that isn't loaded, then the request throws the error

Code Info
unknown_action Unrecognized value for parameter 'action': modulename

You can check to see if a module is available before invoking it, see [How do I] check if an API module is available? in the FAQ.

See also Missing module warnings above.

Parameter validation errors[edit]

The MediaWiki API can "throw" the following errors when validating parameters of any API modules.

Code Info
multival_paramname Only one of 'value1', 'value2', 'value3' is allowed for parameter 'paramname'
unknown_paramname Unrecognized value for parameter paramname: value.
paramname paramname may not be less than min (set to value).
paramname paramname may not be over max (set to value) for bots or sysops.
paramname paramname may not be over max (set to value) for users.
badtimestamp_paramname Invalid value "value" for timestamp parameter paramname.
baduser_paramname Invalid value "value" for user parameter paramname.
invalidparammix The parameters param1, param2, param3 cannot be used together
missingparam One of the parameters param1, param2, param3 is required
_badcontinue Invalid continue param. You should pass the original value returned by the previous query

Standard error messages[edit]

Some generic error messages are shared among modules. If a module can throw these errors, that's explicitly mentioned in its Possible errors section.

Code Info
unknownerror Unknown error: This usually means something crazy like a rare race condition occurred. If you get this error, retry your request until it succeeds or returns a more informative error message
unknownerror Unknown error: "errorcode"
unknownerror-nocode Unknown error
unsupportednamespace Pages in the Special namespace can't be edited
protectednamespace-interface You're not allowed to edit interface messages
protectednamespace You're not allowed to edit pages in the "namespace" namespace
customcssjsprotected You're not allowed to edit custom CSS and JavaScript pages
cascadeprotected The page you're trying to edit is protected because it's included in a cascade-protected page
protectedpage The "right" right is required to edit this page
permissiondenied Permission denied
confirmemail You must confirm your e-mail address before you can edit
blocked You have been blocked from editing
autoblocked Your IP address has been blocked automatically, because it was used by a blocked user
ratelimited You've exceeded your rate limit. Please wait some time and try again
readonly The wiki is currently in read-only mode
badtoken Invalid token (did you remember to urlencode it?)
missingtitle The page you requested doesn't exist
mustbeposted Type of your HTTP request message must be POST
hookaborted The modification you tried to make was aborted by an extension hook
nosuchpageid There is no page with ID id
nosuchrevid There is no revision with ID id
nosuchrcid There is no change with rcid "id"
nosuchuser The user you specified doesn't exist
invalidtitle Bad title "title"
invaliduser Invalid username "username"
assertbotfailed "assert=bot" has been used, but logged in user is not a bot
assertuserfailed "assert=user" has been used, but user is not logged in
readapidenied You need read permission to use this module
noapiwrite Editing of this wiki through the API is disabled. Make sure the $wgEnableWriteAPI=true; statement is included in the wiki's LocalSettings.php file