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 action=tokens with type=import (MW 1.20+), 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 token obtained in the previous request. Take care to urlencode the trailing +\ as %2B%5C
 * : Summary for the import log (optional)
 * : Uploaded XML file (upload)
 * : Wiki to import from (interwiki)
 * The possible values for this parameter differ per wiki, see $wgImportSources. If the list of possible values for this parameter is empty, interwiki imports are disabled
 * : Title of the page to import (interwiki)
 * : If set, import the full history rather than just the current revision (interwiki)
 * : Namespace to import to. If not set, don't change the page's namespace (interwiki)
 * : Import all included templates as well (interwiki)

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)

Possible errors
All errors are formatted as: