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:
ip | cname | UID | Rule |
---|---|---|---|
✔ | ✘ | ✘ | 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:
ip | cname | UID | Rule |
---|---|---|---|
✔ | ✘ | ✘ | 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 reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3)
. - iOS/macOS: The
connectionChangedToState
callback reportsAgoraConnectionChangedBannedByServer(3)
. - Web (3.x): The
Client.on("client-banned")
callback. - Web (4.x): The
Client.on("connection-state-change")
callback. - Windows:The
onConnectionStateChanged
callback reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3)
. - Electron: The
AgoraRtcEngine.on("connectionStateChanged")
callback reports3
. - Unity: The
OnConnectionStateChangedHandler
callback reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3)
. - React Native: The
ConnectionStateChanged
callback reportsBannedByServer(3)
. - Flutter: The
ConnectionStateChanged
callback reportsBannedByServer(3)
. - Cocos Creator: The
onConnectionStateChanged
callback reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3)
. - Applets:
on(event: "client-banned")
.
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:
Parameter | Data type | Required/Optional | Description |
---|---|---|---|
appid | String | Required | The App ID of the project. You can get it through one of the following methods:vendor_key field in the response body. |
cname | String | Optional | The channel name. |
uid | Number | Optional | The user ID. Do not set it as 0 . |
ip | String | Optional | The IP address of the user. Do not set it as 0 . |
time | Number | Required | The time duration (in minutes) to ban the user. The value range is [1,1440]. Note 0 and 1 , Agora automatically sets the value to 1 .1440 , Agora automatically sets the value to 1440 .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.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_seconds | Number | Required | The time duration (in seconds) to ban the user. The value range is [10,86430]. Note 0 and 10 , Agora automatically sets the value to 10 .86430 , Agora automatically sets the value to 86430 .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.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. |
privileges | Array | Required | The 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. 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:
Parameter | Type | Description |
---|---|---|
status | String | The status of this request. success means the request succeeds. |
id | Number | The 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: