Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

Create rule

This method creates a rule for banning specified user privileges.

Prototype

  • Method: POST
  • Endpoint: https://api.agora.io/dev/v1/kicking-rule

The user privileges that can be banned include:

  • join_channel: Joining a channel.

  • publish_audio: Publishing audio.

  • publish_video: Publishing video.

The banning rule works based on the following three fields: cname, uid, and ip.

When you set privileges as join_channel, the rule works as follows:

ipcnameUIDRule
All users with this ip cannot join any channel in the app. Using ip as a filter field may incorrectly block users who should not be blocked, for example, in a scenario where multiple users share an IP address.
No one can join the channel specified by the cname field. Using cname as a filter field directly blocks the channel with the cname.
The user with the UID cannot join any channel in the app.
The user with the UID cannot join the channel specified by the cname field.

When you set privileges as publish_audio or publish_video, the rule works as follows:

ipcnameUIDRule
The users with this ip cannot publish audio or video in any channel of the app.
No one can publish audio or video in the channel specified by the cname field.
The user with the UID cannot publish audio or video in any channel of the app.
The user with the UID cannot publish audio or video in the channel specified by the cname field.

A user who is kicked out of a channel when you set privileges as join_channel receives one of the following callbacks based on their platform:

  • Android: The onConnectionStateChanged callback reports CONNECTION_CHANGED_BANNED_BY_SERVER(3).
  • iOS/macOS: The connectionChangedToState callback reports AgoraConnectionChangedBannedByServer(3).
  • Web (3.x): The Client.on("client-banned") callback.
  • Web (4.x): The Client.on("connection-state-change") callback.
  • Windows:The onConnectionStateChanged callback reports CONNECTION_CHANGED_BANNED_BY_SERVER(3).
  • Electron: The AgoraRtcEngine.on("connectionStateChanged") callback reports 3.
  • Unity: The OnConnectionStateChangedHandler callback reports CONNECTION_CHANGED_BANNED_BY_SERVER(3).
  • React Native: The ConnectionStateChanged callback reports BannedByServer(3).
  • Flutter: The ConnectionStateChanged callback reports BannedByServer(3).
  • Cocos Creator: The onConnectionStateChanged callback reports CONNECTION_CHANGED_BANNED_BY_SERVER(3).
  • Applets: on(event: "client-banned").
Note

To maximize the success rate of core functions, create (POST), update (PUT), and delete (DELETE), the success rate and accuracy of the query (GET) method is degraded to a certain extent when the quality of the public network is abnormally low. Some request records may be missing in the returned results of the query (GET). When calling POST to create a rule (time is not set to 0), which you need to update or delete later, best practice is to:

  • Save the rule ID returned in the POST request on your server, and rely on this ID for subsequent update and delete operations.
  • To ensure that you can still obtain the rule ID returned in the POST request under poor network connections, set the timeout for the POST request to 20 seconds or higher. Make sure that the timeout is set to no less than 5 seconds.
  • In case the POST request times out or returns a 504 error, use the response of the GET method to obtain the rule ID. If the rule exists, it indicates that the POST request is successful, and you can save the rule ID on your server.

Request parameters

Request header

The Content-Type field in all HTTP request headers is application/json. All requests and responses are in JSON format. All request URLs and request bodies are case-sensitive.

The Agora Channel Management RESTful APIs only support HTTPS. Before sending HTTP requests, you must generate a Base64-encoded credential with the Customer ID and Customer Secret provided by Agora, and pass the credential to the Authorization field in the HTTP request header. See RESTful authentication for details.

Request body

Pass in the following parameters in the request body:

ParameterData typeRequired/OptionalDescription
appidStringRequiredThe App ID of the project. You can get it through one of the following methods:
  • Copy from the Agora Console
  • Call the Get all projects API, and read the value of the vendor_key field in the response body.
  • cnameStringOptionalThe channel name.
    uidNumberOptionalThe user ID. Do not set it as 0.
    ipStringOptionalThe IP address of the user. Do not set it as 0.
    timeNumberRequiredThe time duration (in minutes) to ban the user. The value range is [1,1440].

    Note

  • If the set value is between 0 and 1, Agora automatically sets the value to 1.
  • If the set value is greater than 1440, Agora automatically sets the value to 1440.
  • If the set value is 0, the banning rule does not take effect. The server sets all users that conform to the rule offline, and users can log in again to rejoin the channel.
  • Use either time or time_in_seconds. If you set both parameters, the time_in_seconds parameter takes effect; if you set neither of these parameters, the Agora server automatically sets the banning time duration to 60 minutes, that is, 3600 seconds.
  • time_in_secondsNumberRequiredThe time duration (in seconds) to ban the user. The value range is [10,86430].

    Note

  • If the set value is between 0 and 10, Agora automatically sets the value to 10.
  • If the set value is greater than 86430, Agora automatically sets the value to 86430.
  • If the set value is 0, the banning rule does not take effect. The server sets all users that conform to the rule offline, and users can log in again to rejoin the channel.
  • Use either time or time_in_seconds. If you set both parameters, the time_in_seconds parameter takes effect; if you set neither of these parameters, the Agora server automatically sets the banning time duration to 60 minutes, that is, 3600 seconds.
  • privilegesArrayRequiredThe user privileges you want to block. You can choose the following values:
  • join_channel: String. Bans a user from joining a channel or kicks a user out of a channel.
  • publish_audio: String. Bans a user from publishing audio.
  • publish_video: Bans a user from publishing video.
  • You can pass in both publish_audio and publish_video to ban a user from publishing audio and video.

    Request examples

    Test this request in Postman or use one of the following code examples:

    Sample request:

    curl --request POST \
    --url http://api.sd-rtn.com/dev/v1/kicking-rule \
    --header 'Accept: application/json' \
    --header 'Authorization: ' \
    --header 'Content-Type: application/json' \
    --data '{
    "appid": "4855xxxxxxxxxxxxxxxxxxxxxxxxeae2",
    "cname": "channel1",
    "uid": 589517928,
    "ip": "",
    "time": 60,
    "privileges": [
    "join_channel"
    ]
    }'

    Response parameters

    For details about possible response status codes, see Response status codes.

    If the status code is not 200, the request fails. See the message field in the response body for the reason for this failure.

    If the status code is 200, the request succeeds, and the response body includes the following parameters:

    ParameterTypeDescription
    statusStringThe status of this request. success means the request succeeds.
    idNumberThe rule ID. Save the rule ID to update or delete this rule later.

    Response example

    The following is a response example for a successful request:


    _4
    {
    _4
    "status": "success",
    _4
    "id": 1953
    _4
    }

    Voice Calling