question

brendan avatar image
brendan asked

How to ban users via API

Question from a developer:

It's not clear to me from the documentation how to use the BanUsers API call. What's required to make a ban happen for a player?

Account Management
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

The Server and Admin API calls are identical, so I'll use the Server API links in this case, but the same applies to both:

The call itself (https://api.playfab.com/documentation/server/method/BanUsers) has one required field - Bans, which is a list (array) of players to ban. Each element of that array is a BanRequest (https://api.playfab.com/documentation/Server/datatype/PlayFab.Server.Models/PlayFab.Server.Models.BanRequest). In the BanRequest, the only required field is the PlayFab ID of the user, though leaving the DurationInHours blank results in a permanent ban, so you'll want to make use of that if you only want the player banned for a short period. So, if you only wanted to ban one user permanently, and their PlayFab ID was 1234567890, the call would be like so:

POST /Server/BanUsers HTTP/1.1
Host: {TitleId}.playfabapi.com
Content-Type: application/json
X-SecretKey: {SecretKey}
{
  "Bans": [
    {
      "PlayFabId": "1234567890"
    }
  ]
}

If you have the user's IP or MAC Address, you can additionally use those for the ban, to try to prevent the user from creating a new account and continuing to access your title. The Reason is solely for your internal use, as it will not be returned to the player when they get the account banned error (when trying to make any Client API call while banned).

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.