API:Block

Token
To block or unblock a user, a token is required. This token is equal to the edit token and the same for all blocks, but changes at every login. For MediaWiki 1.24 onwards, the needed token can be obtained via meta=tokens with the type set to. For MediaWiki 1.20–1.23, see API:Tokens (action); for older versions, see API:Info.

Blocking users
Users can be blocked with action=block. This must be sent as a POST request. As such, don't forget to append an  to parameters with no value (e.g., , not just  ).

Example
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=block requires POST requests; GET requests will cause an error.

Possible errors
In addition to the usual stuff:

Unblocking users
Users can be unblocked with action=unblock.

Parameters

 * : The ID of the block you want to undo. Block IDs can be obtained through list=blocks
 * : The username, IP address or IP range you want to unblock.
 * : The token obtained in the previous request. Take care to urlencode the  as.
 * : If set, a token will be returned.
 * : The reason for the unblock (optional).

Possible errors
In addition to the usual stuff:


 * code: notarget
 * info: Either the id or the user parameter must be set
 * code: notoken
 * info: The token parameter must be set
 * code: idanduser
 * info: The id and user parameters can't be used together
 * code: blockedasrange
 * info: IP address ``address  was blocked as part of range ``range  . You can't unblock the IP invidually, but you can unblock the range as a whole.
 * code: cantunblock
 * info: The block you specified was not found. It may have been unblocked already
 * code: permissiondenied
 * info: You don't have permission to unblock users
 * On most wikis, unblocking users is restricted to sysops, but other wikis may have stricter rules.