API:Tokens
From MediaWiki.org
| This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Create and edit pages
- Move pages
- Merge pages
- Rollback
- Delete pages
- Restore deleted revisions
- (Un)protect pages
- (Un)block users
- (Un)watch pages
- Mark revisions of watched pages as visited
- Send email
- Patrol changes
- Import pages
- Change user group membership
- Upload files
- User options
- Tokens
- Page language
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
| Tokens | ||
|---|---|---|
| Gets tokens for data-modifying actions. This module cannot be used as a Generator. |
||
| Prefix | ||
| Required rights | none | |
| Post only? | No | |
| Generated help | Current | |
| Version added |
|
|
For the deprecated action module, see API:Tokens (action).
Gets tokens required by data-modifying actions. If you request one of these actions without providing a token, the API returns an error code such as notoken. This module does not use a prefix. The csrf (cross-site request forgery) token corresponds to the majority of older tokens, like edit and move, that were retrieved using the API action tokens (deprecated in MediaWiki 1.24).
Contents
Parameters[edit]
type: Type of token(s) to request. (Default:csrf)csrfwatchpatrolrollbackuserrightslogin1.27+createaccount1.27+
Example[edit]
| Result |
|---|
<?xml version="1.0"?>
<api>
<query>
<tokens csrftoken="00112233445566778899aabbccddeeff+\" />
</query>
</api>
|
| Result |
|---|
<?xml version="1.0"?>
<api>
<query>
<tokens watchtoken="00112233445566778899aabbccddeeff+\" patroltoken="ffeeddccbbaa99887766554433221100+\" />
</query>
</api>
|
Possible errors[edit]
In addition to the usual errors, other errors may be returned in the following format:
<?xml version="1.0"?>
<api batchcomplete="">
<warnings>
<tokens xml:space="preserve">Unrecognized value for parameter <var>type</var>: XXX.</tokens>
</warnings>
<query>
<tokens />
</query>
</api>
Possible errors include:
- Unrecognized value for parameter type: XXX.