Create rule
https://api.agora.io/dev/v1/kicking-rule
Use this endpoint to create a rule for banning specified user privileges.
Request
The request URL and request body is case-sensitive. All requests must use HTTPS.
Request header
Content-Type:application/json- The request header must contain the
Authorizationfield. For details, see RESTful authentication.
Request body
BODYrequired
- appid stringrequired
The 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_keyfield in the response body.
- cname stringnullable
The channel name.
- uid numbernullable
The user ID. Do not set it to
0. - ip stringnullable
The IP address of the user. Do not set it to
0. - time numbernullable
Range:
[1, 1440]The time duration (in minutes) to ban the user. Values outside the range [1,1440] are clamped to the nearest bound. Setting this to
0disables the rule: users are set offline but can rejoin immediately. - time_in_seconds numbernullable
Range:
[10, 86430]The time duration (in seconds) to ban the user. Values outside the range [10,86430] are clamped to the nearest bound. Setting this to
0disables the rule: users are set offline but can rejoin immediately.infoUse either
timeortime_in_seconds, not both. If both are set,time_in_secondstakes effect. If neither is set, the default ban duration is 60 minutes (3600 seconds). - privileges arrayrequired
The user privileges you want to block. Possible values:
join_channel: Bans a user from joining a channel or kicks a user out of a channel.publish_audio: Bans a user from publishing audio.publish_video: Bans a user from publishing video.
To ban a user from both publishing audio and video, specify both
publish_audioandpublish_video.The effect of the banning rule depends on the combination of
cname,uid, andipyou set. See Banning rule behavior for details.When
privilegesis set tojoin_channel, a kicked user receives a connection state change callback on their platform. See Client callbacks forjoin_channelbans for details.
Response
A 200 status code indicates success. The response body contains the following parameters:
OK
If the status code is not 200, the request fails. See the message field in the response body for the reason for this failure. Refer to Response status codes for details.
Reference
Banning rule behavior
The banning rule behavior depends on which combination of cname, uid, and ip fields you set.
When privileges is join_channel:
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 use-case 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 named channel. |
| ✘ | ✘ | ✔ | 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 privileges is publish_audio or publish_video:
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. |
Client callbacks for join_channel bans
A user who is kicked out of a channel when privileges is set to join_channel receives one of the following callbacks based on their platform:
- Android: The
onConnectionStateChangedcallback reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3). - iOS/macOS: The
connectionChangedToStatecallback reportsAgoraConnectionChangedBannedByServer(3). - Web (3.x): The
Client.on("client-banned")callback. - Web (4.x): The
Client.on("connection-state-change")callback. - Windows: The
onConnectionStateChangedcallback reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3). - Electron: The
AgoraRtcEngine.on("connectionStateChanged")callback reports3. - Unity: The
OnConnectionStateChangedHandlercallback reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3). - React Native: The
ConnectionStateChangedcallback reportsBannedByServer(3). - Flutter: The
ConnectionStateChangedcallback reportsBannedByServer(3). - Cocos Creator: The
onConnectionStateChangedcallback reportsCONNECTION_CHANGED_BANNED_BY_SERVER(3). - Applets:
on(event: "client-banned").
Best practices for rule management
To maximize the success rate of create, update, and delete operations, query requests are assigned a lower priority. Under poor network conditions, the success rate and accuracy of GET requests may degrade and some request records may be missing from the results.
When you call POST to create a rule where time is not set to 0, use the following best practices to update or delete it later:
- 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 under poor network conditions, 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
504error, use the response of the GET method to obtain the rule ID. If the rule exists, it indicates that the POST request was successful, and you can save the rule ID on your server.