From MediaWiki.org
Jump to navigation Jump to search

Other languages:
English • ‎dansk • ‎polski • ‎中文 • ‎日本語
MediaWiki version: 1.15

POST request to import a page from another wiki(transwikiing) or from an xml file.

API documentation[edit]


(main | import)
  • This module requires read rights.
  • This module requires write rights.
  • This module only accepts POST requests.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Import a page from another wiki, or from an XML file.

Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when sending a file for the xml parameter.


Log entry import summary.


Uploaded XML file.

Must be posted as a file upload using multipart/form-data.

For uploaded imports: interwiki prefix to apply to unknown user names (and known users if assignknownusers is set).


For interwiki imports: wiki to import from.

One of the following values: meta, w:en, usability

For interwiki imports: page to import.


For interwiki imports: import the full history, not just the current version.

Type: boolean (details)

For interwiki imports: import all included templates as well.

Type: boolean (details)

Import to this namespace. Cannot be used together with rootpage.

One of the following values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 486, 487, 828, 829, 1198, 1199, 2300, 2301, 2302, 2303, 2600, 5500, 5501

Assign edits to local users where the named user exists locally.

Type: boolean (details)

Import as subpage of this page. Cannot be used together with namespace.


Change tags to apply to the entry in the import log and to the null revision on the imported pages.

Values (separate with | or alternative):

A "csrf" token retrieved from action=query&meta=tokens

This parameter is required.


Importing a page is a multi-step process:

  1. Log in using one of the methods described in API:Login .
  2. GET a CSRF token . This token is the same for all pages but changes at every login.
  3. Send a POST request with the CSRF token in order to import the page.

The code samples below cover the third step in detail.

Example 1: Import a page from another wiki[edit]

POST request[edit]

Import Help:ParserFunctions to the Manual namespace (namespace 100) with full history.


  "import": [
      "ns": 12, 
      "revisions": 639, 
      "title": "Help:ParserFunctions"

Sample code[edit]




    MediaWiki Action API Code Samples
    Demo of `Import` module: Import a page from another wiki by
    specifying its title
    MIT license

import requests

S = requests.Session()

URL = "https://test.wikipedia.org/w/api.php"

# Step 1: Retrieve a login token
PARAMS_1 = {
    "action": "query",
    "meta": "tokens",
    "type": "login",
    "format": "json"

R = S.get(url=URL, params=PARAMS_1)
DATA = R.json()

LOGIN_TOKEN = DATA['query']['tokens']['logintoken']

# Step 2: Send a post request to log in using the clientlogin method.
# import rights can't be granted using Special:BotPasswords
# hence using bot passwords may not work.
# See https://www.mediawiki.org/wiki/API:Login for more
# information on log in methods.
PARAMS_2 = {
    'loginreturnurl': '',

R = S.post(URL, data=PARAMS_2)

# Step 3: While logged in, retrieve a CSRF token
PARAMS_3 = {
    "action": "query",
    "meta": "tokens",
    "format": "json"

R = S.get(url=URL, params=PARAMS_3)
DATA = R.json()

CSRF_TOKEN = DATA['query']['tokens']['csrftoken']

# Step 4: Post request to import page from another wiki
PARAMS_4 = {
    "action": "import",
    "format": "json",
    "interwikisource": "meta",
    "interwikipage": "Help:ParserFunctions",
    "token": CSRF_TOKEN

R = S.post(url=URL, data=PARAMS_4)
DATA = R.json()


Example 2: Import a page by uploading its xml dump[edit]

POST request[edit]

Import Help:ParserFunctions by uploading its xml dump obtained from Special:Export.

When uploading a file, you need to use multipart/form-data as Content-Type or enctype, application/x-www-form-urlencoded will not work. The parameter xml is not a file name, but the actual content of a file.


Sample Code[edit]

Possible errors[edit]

In addition to the standard error messages :

Code Info
notoken The token parameter must be set.
cantimport You don't have permission to import pages.
cantimport-upload You don't have permission to import uploaded pages.
nointerwikipage The interwikipage parameter must be set.
nofile You didn't upload a file
filetoobig The file you uploaded is bigger than the maximum upload size
partialupload The file was only partially uploaded
notempdir The temporary upload directory is missing
This generally means the server is broken or misconfigured
cantopenfile Couldn't open the uploaded file
This generally means the server is broken or misconfigured
badinterwiki Invalid interwiki title specified
import-unknownerror Unknown error on import: error.

Parameter history[edit]

  • v1.29: Introduced tags
  • v1.20: Introduced rootpage

Additional notes[edit]

  • This module cannot be used as a generator .
  • importupload rights are required in order to upload an xml file, while import rights are required for interwiki imports.
  • If you get a Missing boundary in multipart/form-data POST data error, it is because you sent it url-encoded but claimed it would be multipart/form-data. MediaWiki is looking for a boundary in the header but cannot find it.
  • Parameters marked with upload are only used when importing an uploaded XML file. Similarly, parameters marked with interwiki are only used when importing from another wiki (transwiki).
  • The possible values for the interwikisource parameter differ per wiki, see Manual:$wgImportSources . If the list of possible values for this parameter is empty, interwiki imports are disabled.

See also[edit]