Skip to main content

Manage chat room block list

A chat room block list refers to a list of users that can neither see nor receive chat room messages. Chat provides a complete set of block list management methods, including adding users to the block list and removing them from it, as well as retrieving the members on the block list.

This page shows how to manage a chat room block list by calling the Chat RESTful APIs. Before calling the following methods, ensure that you understand the call frequency limit described in Limitations.

Common parameters

The following table lists common request and response parameters of the Chat RESTful APIs:

Request parameters

ParameterTypeDescriptionRequired
hostStringThe domain name assigned by the Chat service to access RESTful APIs. For how to get the domain name, see Get the information of your project.Yes
org_nameStringThe unique identifier assigned to each company (organization) by the Chat service. For how to get the org name, see Get the information of your project.Yes
app_nameStringThe unique identifier assigned to each app by the Chat service. For how to get the app name, see Get the information of your project.Yes
usernameStringThe unique login account of the user. The user ID must be 64 characters or less and cannot be empty. The following character sets are supported:
  • 26 lowercase English letters (a-z)
  • 26 uppercase English letters (A-Z)
  • 10 numbers (0-9)
  • "_", "-", "."
  • The username is case insensitive, so Aa and aa are the same username.
  • Ensure that each username under the same app is unique.
Yes
chatroom_idStringThe chat room ID. The unique chat room identifier assigned to each chat room by the Chat. You can get the chat room ID from the response body in Retrieve the basic information of all chat rooms.Yes

Response parameters

ParameterTypeDescription
actionStringThe request method.
organizationStringThe unique identifier assigned to each company (organization) by the Chat service. This is the same as org_name.
applicationStringA unique internal ID assigned to each app by the Chat service. You can safely ignore this parameter.
applicationNameStringThe unique identifier assigned to each app by the Chat service . This is the same as app_name.
uriStringThe request URI.
entities JSONThe response entity.
dataJSONThe details of the response.
timestampNumberThe Unix timestamp (ms) when the user is registered.
durationNumberThe time duration (ms) from sending the HTTP request to receiving the response.
chatroomidStringThe unique identifier of the chat room.

Authorization

Chat RESTful APIs require Bearer HTTP authentication. Every time an HTTP request is sent, the following Authorization field must be filled in the request header:


_1
Authorization: Bearer ${YourAppToken}

In order to improve the security of the project, Agora uses a token (dynamic key) to authenticate users before they log in to the chat system. Chat RESTful APIs only support authenticating users using app tokens. For details, see Authentication using App Token.

Retrieving the chat room block list

Retrieves the block list of the specified chat room.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request


_1
GET https://{host}/{org_name}/{app_name}/chatrooms/{chatroom_id}/blocks/users

Path parameter

For the parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeRequiredDescription
Content-TypeStringYesapplication/json
AuthorizationStringYesThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds, and the data field in the response body contains the usernames in the chat room block list.

If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.

Example

Request example


_1
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users'

Response example


_15
{
_15
"action": "get",
_15
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
_15
"uri": "http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users",
_15
"entities": [],
_15
"data": [
_15
"user2",
_15
"user3"
_15
],
_15
"timestamp": 1543466293681,
_15
"duration": 0,
_15
"organization": "XXXX",
_15
"applicationName": "XXXX",
_15
"count": 2
_15
}

Adding a user to the chat room block list

Adds the specified user to the chat room block list. Once added to the chat room block list, users receive a notification stating "You are kicked out of the chatroom {chatroom_id}" and can no longer join the chat room. They can neither send nor receive messages in the chat room.

You cannot add the chat room owner to the chat room block list.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request


_1
POST https://{host}/{org_name}/{app_name}/chatrooms/{chatroom_id}/blocks/users/{username}

Path parameter

For the parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeRequiredDescription
Content-TypeStringYesapplication/json
AuthorizationStringYesThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds, and the data field in the response body contains the following parameters.

ParameterTypeDescription
resultBooleanWhether the user is successfully added to the chat room block list.
  • true: Yes.
  • false: No.
  • userStringThe username added to the chat room block list.

    For the parameters and detailed descriptions, see Common parameters.

    If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.

    Example

    Request example


    _1
    curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users/user1'

    Response example


    _16
    {
    _16
    "action": "post",
    _16
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _16
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users/user1",
    _16
    "entities": [],
    _16
    "data": {
    _16
    "result": true,
    _16
    "action": "add_blocks",
    _16
    "user": "user1",
    _16
    "chatroomid": "XXXX"
    _16
    },
    _16
    "timestamp": 1542539577124,
    _16
    "duration": 27,
    _16
    "organization": "XXXX",
    _16
    "applicationName": "XXXX"
    _16
    }

    Adding multiple users to the chat room block list

    Adds multiple users to the chat room block list. Once added to the chat room block list, users receive a notification stating "You are kicked out of the chatroom {chatroom_id}" and can no longer join the chat room. They can neither send nor receive messages in the chat room.

    You can add a maximum of 60 users to the chat room block list at one time. You cannot add the chat room owner to the chat room block list.

    For each App Key, the call frequency limit of this method is 100 per second.

    HTTP request


    _1
    POST https://{host}/{org_name}/{app_name}/chatrooms/{chatroom_id}/blocks/users

    Path parameter

    For the parameters and detailed descriptions, see Common parameters. |

    Request header

    ParameterTypeRequiredDescription
    Content-TypeStringYesapplication/json
    AuthorizationStringYesThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.

    Request body

    ParameterTypeDescription
    usernamesArrayThe array of usernames to be added to the chat room block list. You can specify a maximum of 60 usernames, separated by commas (,).

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the data field in the response body contains the following parameters.

    ParameterTypeDescription
    resultBooleanWhether the users are successfully added to the chat room block list.
  • true: Yes.
  • false: No.
  • reasonStringThe reason why the users fail to be added to the chat room block list.
    userStringThe usernames added to the chat room block list.

    For the parameters and detailed descriptions, see Common parameters.

    If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.

    Example

    Request example


    _5
    curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' -d '{
    _5
    "usernames": [
    _5
    "user3","user4"
    _5
    ]
    _5
    }' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users'

    Response example


    _25
    {
    _25
    "action": "post",
    _25
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _25
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users",
    _25
    "entities": [],
    _25
    "data": [
    _25
    {
    _25
    "result": false,
    _25
    "action": "add_blocks",
    _25
    "reason": "user: user3 doesn't exist in chatroom: XXXX",
    _25
    "user": "user3",
    _25
    "chatroomid": "XXXX"
    _25
    },
    _25
    {
    _25
    "result": true,
    _25
    "action": "add_blocks",
    _25
    "user": "user4",
    _25
    "chatroomid": "XXXX"
    _25
    }
    _25
    ],
    _25
    "timestamp": 1542540095540,
    _25
    "duration": 16,
    _25
    "organization": "XXXX",
    _25
    "applicationName": "XXXX"
    _25
    }

    Removing a user from the chat room block list

    Removes the specified user from the chat room block list. To add a user that is in the block list back to the chat room, you need to remove that user from the block list first.

    For each App Key, the call frequency limit of this method is 100 per second.

    HTTP request


    _1
    DELETE https://{host}/{org_name}/{app_name}/chatrooms/{chatroom_id}/blocks/users/{username}

    Path parameter

    For the parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeRequiredDescription
    Content-TypeStringYesapplication/json
    AuthorizationStringYesThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the data field in the response body contains the following parameters.

    ParameterTypeDescription
    resultBooleanWhether the user is successfully removed from the chat room block list.
  • true: Yes.
  • false: No.
  • userStringThe username removed from the chat room block list.

    For the parameters and detailed descriptions, see Common parameters.

    If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.

    Example

    Request example


    _1
    curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users/user1'

    Response example


    _16
    {
    _16
    "action": "delete",
    _16
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _16
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users/user1",
    _16
    "entities": [],
    _16
    "data": {
    _16
    "result": true,
    _16
    "action": "remove_blocks",
    _16
    "user": "user1",
    _16
    "chatroomid": "XXXX"
    _16
    },
    _16
    "timestamp": 1542540470679,
    _16
    "duration": 45,
    _16
    "organization": "XXXX",
    _16
    "applicationName": "XXXX"
    _16
    }

    Removing multiple users from the chat room block list

    Removes the specified users from the chat room block list. To add users that are in the block list back to the chat room, you need to remove these users from the block list first. You can remove a maximum of 60 users from the chat room block list at one time.

    For each App Key, the call frequency limit of this method is 100 per second.

    HTTP request


    _1
    DELETE https://{host}/{org_name}/{app_name}/chatrooms/{chatroom_id}/blocks/users/{usernames}

    Path parameter

    For the parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeRequiredDescription
    Content-TypeStringYesapplication/json
    AuthorizationStringYesThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.

    Request body

    If the returned HTTP status code is 200, the request succeeds, and the data field in the response body contains the following parameters.

    ParameterTypeRequiredDescription
    usernameStringYesThe usernames to be removed from the chat room block list. You can specify a maximum of 60 usernames, separated by commas (,).

    HTTP response

    Response body

    If the returned HTTP status code is 200, the request succeeds, and the data field in the response body contains the following parameters.

    ParameterTypeDescription
    resultBooleanWhether the users are successfully removed from the chat room block list.
  • true: Yes.
  • false: No.
  • userStringThe usernames removed from the chat room block list.

    For the parameters and detailed descriptions, see Common parameters.

    If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.

    Example

    Request example


    _1
    curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users/user1%2Cuser2'

    Response example


    _24
    {
    _24
    "action": "delete",
    _24
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _24
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/XXXX/blocks/users/user1%2Cuser2",
    _24
    "entities": [],
    _24
    "data": [
    _24
    {
    _24
    "result": true,
    _24
    "action": "remove_blocks",
    _24
    "user": "user1",
    _24
    "chatroomid": "XXXX"
    _24
    },
    _24
    {
    _24
    "result": true,
    _24
    "action": "remove_blocks",
    _24
    "user": "user2",
    _24
    "chatroomid": "XXXX"
    _24
    }
    _24
    ],
    _24
    "timestamp": 1542541014655,
    _24
    "duration": 29,
    _24
    "organization": "XXXX",
    _24
    "applicationName": "XXXX"
    _24
    }

    Status codes

    For details, see HTTP Status Code.