Manage chat rooms
This page shows how to manage chat rooms by calling Chat RESTful APIs, including adding, deleting, modifying, and retrieving chat rooms.
Before calling the following methods, ensure that you understand the frequency limit of calling Chat RESTful API calls described in Limitations.
Common parameters
The following table lists common request and response parameters of the Chat RESTful APIs:
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
host | String | The 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_name | String | The 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_name | String | The 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 |
username | String | The 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:
| Yes |
Response parameters
Parameter | Type | Description |
---|---|---|
action | String | The request method. |
organization | String | The unique identifier assigned to each company (organization) by the Chat service. This is the same as org_name . |
application | String | A unique internal ID assigned to each app by the Chat service. You can safely ignore this parameter. |
applicationName | String | The unique identifier assigned to each app by the Chat service . This is the same as app_name . |
uri | String | The request URI. |
path | String | The request path, which is part of the request URL. You can safely ignore this parameter. |
entities | JSON | The response entity. |
timestamp | Number | The Unix timestamp (ms) of the HTTP response. |
duration | Number | The duration (ms) from when the HTTP request is sent to the time the response is received. |
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:
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.
Creating a chat room
Creates a chat room.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | application/json | Yes |
Content-Type | String | application/json | Yes |
Authorization | String | The 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. | Yes |
Request body
The request body is a JSON object, which contains the following fields:
Field | Type | Description | Required |
---|---|---|---|
name | String | The chat room name which can contain a maximum of 128 characters. | Yes |
description | String | The chat room description which can contain a maximum of 512 characters. | Yes |
maxusers | Int | The maximum number of members (including the chat room owner) that can join a chat room. The value range is [1,10,000], with 1000 as the default. To increase the upper limit, contact support@agora.io. | No |
owner | String | The username of the chat room creator. | Yes |
members | JSONArray | The array of user IDs of regular chat room members and administrators, excluding the chat room owner. If you specify this parameter, remember to pass in at least one user ID. The number of user IDs in the array cannot exceed the value of maxusers . | No |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Field | Type | Description |
---|---|---|
id | String | The chat room ID. This is the unique identifier assigned to each chat room by the Chat service. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieving basic information of all chat rooms
Retrieves the basic information of all chat rooms under the app by page.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters .
Query parameters
parameter | type | describe | Is it required? |
---|---|---|---|
limit | Number | The number of chat rooms expected to be fetched each time. The value range is [1,100], the default is 10 , This parameter is only required when fetching pages. | No |
cursor | String | The starting position for data query. This parameter is required only for paginated queries. For the first query, you do not need to set cursor and the server returns chat rooms of the number specified with limit in the descending order of their creation time. You can get the cursor from the response body and pass it in the URL of the next query request. If there is no longer a cursor field in the response body, all chat rooms in the app are retrieved. | No |
If neither is set in the request limit and cursor , before the server returns the first page of the chat room list 10 chat room. |
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | application/json | Yes |
Authorization | String | The 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. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds. The response body contains the following fields:
Field | Type | Description |
---|---|---|
id | String | The chat room ID. This is the unique identifier assigned to the chat room by the Chat. |
name | String | The chat room name. |
owner | String | The username of the chat room creator. |
affiliations_count | Number | The number of members (including the chat room creator) in the chat room. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieving chat rooms that a user joins
Retrieves all the chat rooms that a user joins.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters .
Query parameter
Parameter | Type | Description | Required |
---|---|---|---|
pagenum | Number | The page number on which chat rooms are to be retrieved. | No |
pagesize | Number | The number of chat rooms to be retrieved each time. The value range is [1,1000], with 1000 as the default. | No |
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | application/json | Yes |
Authorization | String | The 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. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds. The response body contains the following fields:
Field | Type | Descriptions |
---|---|---|
id | String | The ID of the chat room that the user joins. This is the unique identifier assigned to each chat room by the Chat. |
name | String | The name of the chat room that the user joins. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieving detailed information of the specified chat rooms
Retrieves the detailed information of one or more specified chat rooms.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
chatroom_id | String | The chat room ID. The unique identifier assigned to each chat room by the Chat service. You can get the chat room ID from the response body of Retrieve basic information of all chat rooms.chatroom_id ) separated with the comma (,). | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | application/json | Yes |
Authorization | String | The 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. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds. The response body contains the following fields:
Field | Type | Description |
---|---|---|
id | String | The chat room ID. |
name | String | The chat room name. |
description | String | The chat room description. |
membersonly | Bool | Whether a user requesting to join the chat room requires approval from the chat room administrator.true : Yesfalse : No |
allowinvites | Bool | Whether to allow a chat room member to invite others to join the chat room.true : A chat room member can invite others to join the chat room.false : Only the chat room administrator can invite others to join the chat room. |
maxusers | Int | The maximum number of members that can join the chat room. |
owner | String | The username of the chat room creator. |
created | Number | The Unix timestamp (ms) when the chat room is created. |
custom | String | Custom information added during creation of the chat room. |
affiliations_count | Number | The number of members (including the chat room creator) in the chat room. |
affiliations | JSONArray | The chat room member array, which contains the following fields:owner : The username of the chat room creator.member : The username of each chat room member. |
public | Bool | It is a reserved parameter. You can safely ignore this parameter. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Modifying chat room information
Modifies the information of the specified chat room. You can only modify the name
, description
, and maxusers
of a chat room.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
chatroom_id | String | The chat room ID. The unique identifier assigned to each chat room by the Chat service. You can get the chat room ID from the response body of Retrieve basic information of all chat rooms. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | application/json | Yes |
Accept | String | application/json | Yes |
Authorization | String | The 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. | Yes |
Request body
The request body is a JSON object which only contains the following fields:
Field | Type | Description | Required |
---|---|---|---|
name | String | The chat room name. | No |
description | String | The chat room description. | No |
maxusers | Number | The maximum number of chat room members (including the chat room creator). | No |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds and the response body contains the following fields:
Field | Type | Description |
---|---|---|
groupname | Bool | Whether the chat room name is successfully changed.true : Successfalse : Failure |
description | Bool | Whether the chat room description is successfully modified.true : Successfalse : Failure |
maxusers | Bool | Whether the maximum number of members that can join the chat room is successfully changed.true : Successfalse : Failure |
If the returned HTTP status code is not 200
, the request failed. You can refer to Status codes for possible reasons.
If other fields than
name
,description
, andmaxusers
are passed in the request body, the request fails and the error code400
is returned.
Example
Request example
Response example
Deleting the specified chat room
Deletes the specified chat room. If the specified chat room does not exist, an error returns.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
chatroom_id | String | The chat room ID. The unique identifier assigned to each chat room by the Chat service. You can get the chat room ID from the response body of Retrieve basic information of all chat rooms. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | application/json | Yes |
Authorization | String | The 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. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds and the response body contains the following fields:
Field | Type | Description |
---|---|---|
success | Bool | Whether the chat room is successfully deleted.true : Successfalse : Failure |
id | String | The ID of the chat room that is deleted. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieving a chat room announcement
Retrieves the announcement text for the specified chat room.
HTTP request
Path parameter
Parameter | Type | Required | Description |
---|---|---|---|
chatroom_id | String | Yes | The chat room ID. The unique identifier assigned to each chat room by the Chat service. You can get the chat room ID from the response body of Retrieve basic information of all chat rooms. |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Required | Description |
---|---|---|---|
Content-Type | String | Yes | Set to application/json . |
Accept | String | Yes | application/json |
Authorization | String | Yes | The 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
The response body contains the following fields:
Parameter | Type | Description |
---|---|---|
data.announcement | String | The announcement text of the specified chat room. |
Example
Request example
Response example
Modifying the announce of a chat room
Modifies the announcement text of the specified chat room. The length cannot exceed 512 characters.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
chatroom_id | String | The chat room ID. The unique identifier assigned to each chat room by the Chat service. You can get the chat room ID from the response body of Retrieve basic information of all chat rooms. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Required | Description |
---|---|---|---|
Content-Type | String | Yes | Set to application/json . |
Authorization | String | Yes | The 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
Parameter | Type | Required | Description |
---|---|---|---|
announcement | String | Yes | The modified announcement text. |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
data.id | String | The chat room ID. |
data.result | Boolean | Whether the chat room announcement is successfully modified: - true : Success- false : Failure |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Status codes
For details, see HTTP Status Codes.