API:Tokens (action)

From mediawiki.org
Jump to navigation Jump to search
Other languages:
Deutsch • ‎Deutsch (Sie-Form)‎ • ‎English • ‎Türkçe • ‎dansk • ‎español • ‎français • ‎polski • ‎português • ‎română • ‎русский • ‎کوردی • ‎ไทย • ‎中文 • ‎日本語
Since MW 1.24, the action=tokens is deprecated and includes a warning "Please use action=query&meta=tokens instead".

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

Parameters[edit]

  • type: the type of token requested.
    • block
    • delete
    • edit
    • email
    • import
    • move
    • options
    • patrol
    • protect
    • rollback
    • unblock
    • watch

      The Central Auth extension on MediaWiki servers adds the following tokens:
    • deleteglobalaccount
    • setglobalaccountstatus

Examples[edit]

Getting an edit token (default behavior)

Getting several tokens at once

Possible errors[edit]

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 <var>type</var>: test.</tokens>
   </warnings>
   <tokens/>
</api>

Possible errors include:

  • Unrecognized value for parameter type: value.
  • Action "xxx" is not allowed for the current user.

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

Important Note[edit]

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

API documentation[edit]


action=tokens

(main | tokens)
  • This module is deprecated.
  • This module requires read rights.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Get tokens for data-modifying actions.

This module is deprecated in favor of action=query&meta=tokens.

Parameter:
type

Types of token to request.

Values (separate with | or alternative): block, createaccount, csrf, delete, deleteglobalaccount, edit, email, import, login, move, options, patrol, protect, rollback, setglobalaccountstatus, unblock, userrights, watch
Default: edit
Examples:
Retrieve an edit token (the default).
api.php?action=tokens [open in sandbox]
Retrieve an email token and a move token.
api.php?action=tokens&type=email|move [open in sandbox]