API:Data formats

From MediaWiki.org
Jump to: navigation, search
This page contains changes which are not marked for translation.

Language: English  • Deutsch • español • français • 日本語 • 한국어 • русский • українська
Tools clipart.png This page is part of the MediaWiki API documentation.
MediaWiki API

Quick overview:

v · d · e

Input[edit | edit source]

The API takes its input through parameters provided by the query string or from a POST entity in application/x-www-form-urlencoded or multipart/form-data format. Every module (and every action=query submodule) has its own set of parameters, which is listed in the documentation and in action=help, and can be retrieved through action=paraminfo.

Multivalue parameters[edit | edit source]

Some parameters take multiple values, separated by a pipe character (|). Whether a parameter accepts multiple values is listed explicitly in action=paraminfo and action=help. The documentation does not distinguish multivalue parameters explicitly, but the descriptions for these parameters are usually along the lines of "A list of ..." or "A pipe-separated list of ...".

Timestamps[edit | edit source]

Parameters that take timestamp values accept multiple timestamp formats:

In the output, timestamps are always in ISO 8601 format.

Output[edit | edit source]

MediaWiki API supports a number of generic output formats (XML, JSON, YAML, ...), and some domain specific formats (RSS, ...) for special modules. Starting with version 1.24, all formats other than JSON, XML and PHP are deprecated and are scheduled for removal in 1.26 and 1.27. All new API users should use JSON. Clients written in PHP should avoid using the PHP format because it is fundamentally insecure. It is maintained only due to its popularity.

Unless specified, all modules allow data output in all generic formats. To simplify debugging, all generic formats have "pretty-print in HTML" alternatives with 'fm' suffix. By default, jsonfm format is used.

Note that while the pretty-print formats are all indented and separate syntactic elements with newlines, the non-pretty formats don't do this.

Code Description Parameters
json JSON format callback (opt): Wraps the output into a given function call
php serialized PHP format
xml XML format
Deprecated formats
wddx WDDX format
yaml YAML format
txt PHP print_r() format
dbg PHP var_export() format
dump PHP var_dump() format

CSV format can easily be derived from json responses using a converter such as json-csv.com.

JSON parameters[edit | edit source]

Unlike the other formats, the two JSON formats can take the following additional parameters:

  • callback: If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.
  • utf8: If specified, encodes most (but not all) non-ASCII characters as UTF-8 instead of replacing them with hexadecimal escape sequences.

Callback restrictions[edit | edit source]

When using JSON in callback mode, a number of things are disabled for security:

  • Tokens cannot be obtained (so state-changing actions aren't possible)
  • The client is treated as an anonymous user (i.e. not logged in) for all purposes, even after logging in through action=login
    • This means that things that require additional rights, such as rcprop=patrolled, won't work unless anonymous users are allowed to use them

Examples[edit | edit source]



it may be useful to add the '&indexpageids' parameter, to parse the json if the pageid ("736") is not known before the result.


PHP (serialized format, with line breaks added for readability. Use PHP's unserialize() function to recover data.)

PHP (var_export format. Use PHP's eval() function to recover data.)