API:Import

Token
To import pages, an import token is required. This token is equal to the edit token and the same for all pages, but changes at every login. Import tokens can be obtained via, or by using the following method:

Importing pages
Pages can be imported with action=import, either by uploading an XML file or by specifying a page from another wiki (also known as transwikiing).

Parameters
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 this parameter differ per wiki, see . If the list of possible values for this parameter is empty, interwiki imports are disabled
 * The possible values for this parameter differ per wiki, see . If the list of possible values for this parameter is empty, interwiki imports are disabled
 * The possible values for this parameter differ per wiki, see . If the list of possible values for this parameter is empty, interwiki imports are disabled
 * The possible values for this parameter differ per wiki, see . If the list of possible values for this parameter is empty, interwiki imports are disabled

Example
Note: In these examples, all parameters are passed in a GET request just for the sake of simplicity. However, action=import requires POST requests; GET requests will cause an error.

XML file
When uploading a file, you need to use  as Content-Type or enctype,   will not work. The parameter xml is not a file name, but the actual content of a file.

Ruby source code example using httpclient (assumes login cookies are already in @headers)

FormData
If the result says "no file" it is expecting a file in a POST body. You can easily POST using FormData.

To quote from /api.php xml     - Uploaded XML file Must be posted as a file upload using multipart/form-data

JavaScript example
For simplicity, the following code is reading the XML from a textarea and makes use of MediaWiki's JavaScript includes:

This is just a minimal implementation. Do not forget error-handling. If you have the exports as files for upload and want to make it working in older browsers not sufficiently supporting Blobs and FormData, just build a HTML form. The form's target could be an iframe so you can read the response from it without exposing the blank API result page to your users.

Raw request resulting
The request that is composed by the client and sent to the server for reference. Note the file's in a POST body.

POST http://localhost/api.php HTTP/1.1 Host: localhost User-Agent: Accept-Language: de,en-US;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate Referer: http://localhost/index.php?title=Special:Export&action=submit Content-Length: 3231 Content-Type: multipart/form-data; boundary=-768648126486 Cookie: ; mwdbUserID=1; mwdbUserName=Rillke Connection: keep-alive Pragma: no-cache Cache-Control: no-cache

---768648126486 Content-Disposition: form-data; name="format"

json ---768648126486 Content-Disposition: form-data; name="action"

import ---768648126486 Content-Disposition: form-data; name="xml"; filename="file.xml" Content-Type: text/xml

 Sample Wiki

---768648126486 Content-Disposition: form-data; name="token"

XX39e9fd22a9de7675c71eadcfd2XXXX+\ ---768648126486--

This 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.
 * "Missing boundary in multipart/form-data POST data" error?

Possible errors
All errors are formatted as: