API:Block

Token
To (un)block a user, a(n) (un)block token is required. This token is equal to the edit token and the same for all blocks, but changes at every login. A(n) (un)block token can be obtained via action=tokens with the type set to (un)block (MW 1.20+), or by using the following method:

Blocking users
Users can be blocked with action=block.

Parameters

 * : The username, IP address or IP range you want to block.
 * : The token obtained in the previous request. Take care to urlencode the  as.
 * : Expiry timestamp. Relative expiry times, like  or   are also accepted. If set to ,  ,  , or not set at all, the block will never expire.
 * : The reason for the block (optional).
 * : If set, only anonymous logins from the user's IP will be blocked, thus forcing the user to log in or create an account in order to be able to edit.
 * : If set, block account creation from the user's IP.
 * : If set, automatically block the IP address last used by this user, and any subsequent IPs they try to login from.
 * : If set, prevent the user from sending email through Special:Emailuser.
 * : Hide the username from the block log. (Requires the "hideuser" right.)
 * : Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)
 * : If the user is already blocked, overwrite the existing block
 * : Watch the user/IP's user and talk pages

Don't forget to append = even to parameters with no value, for example &autoblock doesn't work, &autoblock= does work

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.