API:Tokens

From MediaWiki.org
Jump to: navigation, search
Tools clipart.png This page is part of the MediaWiki API documentation.
Language: English  • 日本語
MediaWiki API

Quick overview:

v · d · e
MediaWiki version: 1.20

Obtaining tokens[edit | edit source]

Tokens can be obtained using action=tokens. These tokens can then be used in other API requests.

Parameters[edit | edit source]

  • type: the type of token requested. Options:
  • block
  • centralauth
  • delete
  • deleteglobalaccount
  • edit
  • email
  • import
  • move
  • options
  • patrol
  • protect
  • setglobalaccountstatus
  • unblock
  • watch

Examples[edit | edit source]

Getting an edit token (default behavior)

Getting several tokens at once

Possible errors[edit | edit source]

In addition to the usual errors, other errors may be returned in the following format:

<?xml version="1.0"?>
<api>
   <warnings>
      <tokens>Unrecognized value for parameter 'type': test</tokens>
   </warnings>
   <tokens/>
</api>

Possible errors include:

  • Unrecognized value for parameter 'type'
  • Action 'xxx' is not allowed for the current user

Failing to urlencode the token can result in an invalid token error.

Important Note[edit | edit source]

You need to send the cookie obtained in the login phase when you do call the api with the "tokens" action; otherwise you get the cryptic "readapidenied" error.

See also[edit | edit source]

Language: English  • 日本語