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 the following ways:

Blocking users
Users can be blocked with action=block.

Parameters

 * user: The username, IP address or IP range you want to block.
 * token: The token obtained in the previous request. Take care to urlencode the '+' as '%2B'.
 * gettoken: If set, a token will be returned. See also the previous request.
 * expiry: Relative expiry time, e.g. '5 months' or '2 weeks'. Years, days and hours are also accepted. If set to, 'infinite', 'infinity', 'never', or not set at all, the block will never expire.
 * reason: The reason for the block (optional).
 * anononly: 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.
 * nocreate: If set, block account creation from the user's IP.
 * autoblock: If set, automatically block the IP address last used by this user, and any subsequent IPs they try to login from.
 * noemail: If set, prevent the user from sending email through Special:Emailuser.

Possible errors
All errors are formatted as:


 * code: nouser
 * info: The user parameter must be set
 * code: notoken
 * info: The token parameter must be set
 * code: permissiondenied
 * info: You don't have permission to block users
 * On most wikis, blocking users is restricted to sysops, but other wikis may have stricter rules.
 * code: nohide
 * info: You don't have permission to hide user names from the block log
 * This feature has to be enabled explicitly in LocalSettings.php.
 * code: readonly
 * info: The wiki is in read-only mode
 * In read-only mode, absolutely nothing can be changed.
 * code: badtoken
 * info: Invalid token
 * code: invalidrange
 * info: Invalid IP range ``range ''
 * IP ranges must be formatted as nnn.nnn.0.0/16 or nnn.0.0.0/24
 * code: rangedisabled
 * info: Blocking IP ranges has been disabled
 * code: nosuchuser
 * info: User ``user '' doesn't exist
 * This may happen when trying to block an invalid IP address.
 * code: invalidip
 * info: Invalid IP address ``ip ''
 * code: invalidexpiry
 * info: Invalid expiry time ``expiry ''
 * code: alreadyblocked
 * info: User ``user '' is already blocked

Unlocking users
Users can be unblocked with action=unblock.

Parameters

 * id: The ID of the block you want to undo. Block IDs can be obtained through list=ipblocks.
 * user: The username, IP address or IP range you want to unblock.
 * token: The token obtained in the previous request. Take care to urlencode the '+' as '%2B'.
 * gettoken: If set, a token will be returned. See also the previous request.
 * reason: The reason for the unblock (optional).

Possible errors
All errors are formatted as:


 * code: notarget
 * info: Either the id or the user parameter must be set
 * code: idanduser
 * info: The id and user parameters can't be used together
 * code: notoken
 * info: The token parameter must be set
 * code: permissiondenied
 * info: You don't have permission to block users
 * On most wikis, unblocking users is restricted to sysops, but other wikis may have stricter rules.
 * code: readonly
 * info: The wiki is in read-only mode
 * In read-only mode, absolutely nothing can be changed.
 * code: badtoken
 * info: Invalid token
 * code: nosuchid
 * info: There is no block with ID ``id ''
 * code: notblocked
 * info: User ``user '' is not blocked
 * code: unknownerr
 * info: Unknown error
 * This usually means some very rare coincidence occurred. Try the same request again, and you'll get a sensible error message.