Jump to content

API:Tokens: Difference between revisions

From mediawiki.org
Content deleted Content added
Tegel (talk | contribs)
m Reverted edits by 174.237.1.120 (talk) to last revision by Kaganer
Tag: Rollback
AbyxDev (talk | contribs)
updated XML response to JSON
Line 35: Line 35:
|p1=action=query
|p1=action=query
|p2=meta=tokens
|p2=meta=tokens
|result=<source lang="xml"><?xml version="1.0"?>
|result=<source lang="json">{
"batchcomplete": "",
<api>
<query>
"query": {
"tokens": {
<tokens csrftoken="00112233445566778899aabbccddeeff+\" />
"csrftoken": "70b9d5a379492c0a07da48650d8906915ad5dbad+\\"
</query>
}
</api></source>}}
}
}</source>}}


{{TNT|ApiEx
{{TNT|ApiEx
Line 47: Line 49:
|p2=meta=tokens
|p2=meta=tokens
|p3=type=watch{{!}}patrol
|p3=type=watch{{!}}patrol
|result=<source lang="xml"><?xml version="1.0"?>
|result=<source lang="json">{
"batchcomplete": "",
<api>
<query>
"query": {
"tokens": {
<tokens watchtoken="00112233445566778899aabbccddeeff+\" patroltoken="ffeeddccbbaa99887766554433221100+\" />
"watchtoken": "585239d7acb985eca442a34abbebfbe25ad5dbd1+\\",
</query>
"patroltoken": "74c5001ef3dd19723547070cab2707945ad5dbd1+\\"
</api></source>}}
}
}
}</source>}}


<translate>
<translate>

== Possible errors == <!--T:15-->
== Possible errors == <!--T:15-->



Revision as of 11:35, 17 April 2018

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).

Parameters

  • type: Type of token(s) to request. (Default: csrf)
    • csrf
    • watch
    • patrol
    • rollback
    • userrights
    • login 1.27+
    • createaccount 1.27+

Example

Result
{
    "batchcomplete": "",
    "query": {
        "tokens": {
            "csrftoken": "70b9d5a379492c0a07da48650d8906915ad5dbad+\\"
        }
    }
}
Result
{
    "batchcomplete": "",
    "query": {
        "tokens": {
            "watchtoken": "585239d7acb985eca442a34abbebfbe25ad5dbd1+\\",
            "patroltoken": "74c5001ef3dd19723547070cab2707945ad5dbd1+\\"
        }
    }
}


Possible errors

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.

See also