Skip to main content
Android
iOS
Web
Windows
Unity
Flutter
React Native

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

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

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.
pathStringThe request path, which is part of the request URL. You can safely ignore this parameter.
entities JSONThe response entity.
timestampNumberThe Unix timestamp (ms) of the HTTP response.
durationNumberThe 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:


_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.

Creating a chat room

Creates a chat room.

HTTP request


_1
POST https://{host}/{org_name}/{app_name}/chatrooms

Path parameter

For the parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeDescriptionRequired
AcceptStringapplication/jsonYes
Content-TypeStringapplication/jsonYes
AuthorizationStringThe 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:

FieldTypeDescriptionRequired
nameStringThe chat room name which can contain a maximum of 128 characters.Yes
descriptionStringThe chat room description which can contain a maximum of 512 characters.Yes
maxusersIntThe 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
ownerStringThe username of the chat room creator.Yes
membersJSONArrayThe 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:

FieldTypeDescription
idStringThe 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


_10
# Replace <YourAppToken> with the app token you generated on the server
_10
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' -d '{
_10
"name": "testchatroom1",
_10
"description": "test",
_10
"maxusers": 300,
_10
"owner": "user1",
_10
"members": [
_10
"user2"
_10
]
_10
}' 'http://XXXX/XXXX/XXXX/chatrooms'

Response example


_5
{
_5
"data": {
_5
"id": "66213271109633"
_5
}
_5
}

Retrieving basic information of all chat rooms

Retrieves the basic information of all chat rooms under the app by page.

HTTP request


_1
GET https://{host}/{org_name}/{app_name}/chatrooms?limit={N}&cursor={cursor}

Path parameter

For the parameters and detailed descriptions, see Common parameters .

Query parameters

parametertypedescribeIs it required?
limitNumberThe 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
cursorStringThe 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

ParameterTypeDescriptionRequired
AcceptStringapplication/jsonYes
AuthorizationStringThe 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:

FieldTypeDescription
idStringThe chat room ID. This is the unique identifier assigned to the chat room by the Chat.
nameStringThe chat room name.
ownerStringThe username of the chat room creator.
affiliations_countNumberThe 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


_3
# Replace <YourAppToken> with the app token you generated on the server
_3
curl --location --request GET 'http://XXXX/XXXX/XXXX/chatrooms?limit=10' \
_3
--header 'Authorization: Bearer <YourAppToken

Response example


_40
{
_40
"action": "get",
_40
"application": "2a8f5b13-XXXX-XXXX-958a-838fd47f1223",
_40
"applicationName": "chatdemoui",
_40
"count": 3,
_40
"data": [
_40
{
_40
"affiliations_count": 1,
_40
"disabled": false,
_40
"id": "212126099636225",
_40
"name": "testchatroom1",
_40
"owner": "yifan1"
_40
},
_40
{
_40
"affiliations_count": 1,
_40
"disabled": false,
_40
"id": "212126098587649",
_40
"name": "testchatroom2",
_40
"owner": "yifan1"
_40
},
_40
{
_40
"affiliations_count": 1,
_40
"disabled": false,
_40
"id": "212126095441921",
_40
"name": "testchatroom3",
_40
"owner": "yifan1"
_40
}
_40
],
_40
"duration": 1,
_40
"entities": [],
_40
"organization": "XXXX",
_40
"params": {
_40
"limit": [
_40
"5"
_40
]
_40
},
_40
"properties": {},
_40
"timestamp": 1681697615739,
_40
"uri": "http://a1-hsb.easemob.com/easemob-demo/chatdemoui/chatrooms"
_40
}

Retrieving chat rooms that a user joins

Retrieves all the chat rooms that a user joins.

HTTP request


_1
GET https://{host}/{org_name}/{app_name}/users/{username}/joined_chatrooms?pagenum={N}&pagesize={N}

Path parameter

For the parameters and detailed descriptions, see Common parameters .

Query parameter

ParameterTypeDescriptionRequired
pagenumNumberThe page number on which chat rooms are to be retrieved.No
pagesizeNumberThe number of chat rooms to be retrieved each time. The value range is [1,1000], with 1000 as the default.No
If neither query parameter is specified, the server returns the 500 chat rooms that the user joined most recently.

Request header

ParameterTypeDescriptionRequired
AcceptStringapplication/jsonYes
AuthorizationStringThe 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:

FieldTypeDescriptions
idStringThe ID of the chat room that the user joins. This is the unique identifier assigned to each chat room by the Chat.
nameStringThe 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


_2
# Replace <YourAppToken> with the app token generated in your server.
_2
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/users/XXXX/joined_chatrooms'

Response example


_6
{
_6
"data": {
_6
"id": "66211860774913",
_6
"name": "test"
_6
}
_6
}

Retrieving detailed information of the specified chat rooms

Retrieves the detailed information of one or more specified chat rooms.

HTTP request


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

Path parameter

ParameterTypeDescriptionRequired
chatroom_idStringThe 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.
  • When retrieving multiple chat rooms, type multiple chatroom IDs (chatroom_id) separated with the comma (,).
  • A maximum of 100 chat rooms can be retrieved at one go.
  • In the URL, "," needs to be escaped as "%2C".
  • Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringapplication/jsonYes
    AuthorizationStringThe 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:

    FieldTypeDescription
    idStringThe chat room ID.
    nameStringThe chat room name.
    descriptionStringThe chat room description.
    membersonlyBoolWhether a user requesting to join the chat room requires approval from the chat room administrator.
  • true: Yes
  • false: No
  • allowinvitesBoolWhether 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.
  • maxusersIntThe maximum number of members that can join the chat room.
    ownerStringThe username of the chat room creator.
    createdNumberThe Unix timestamp (ms) when the chat room is created.
    customStringCustom information added during creation of the chat room.
    affiliations_countNumberThe number of members (including the chat room creator) in the chat room.
    affiliationsJSONArrayThe 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.
  • publicBoolIt 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


    _2
    # Replace <YourAppToken> with the app token generated in your server.
    _2
    curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX%2CXXXX'

    Response example


    _52
    {
    _52
    "action": "get",
    _52
    "application": "22bcffa0-XXXX-XXXX-9df8-516f6df68c6d",
    _52
    "applicationName": "XXXX",
    _52
    "count": 2
    _52
    "data": [
    _52
    {
    _52
    "id": "XXXX",
    _52
    "name": "testchatroom1",
    _52
    "description": "test",
    _52
    "membersonly": false,
    _52
    "allowinvites": false,
    _52
    "maxusers": 1000,
    _52
    "created": 1641365888209,
    _52
    "custom": "",
    _52
    "affiliations_count": 2,
    _52
    "affiliations": [
    _52
    {
    _52
    "member": "user1"
    _52
    },
    _52
    {
    _52
    "owner": "user2"
    _52
    }
    _52
    ],
    _52
    "public": true
    _52
    },
    _52
    {
    _52
    "id": "XXXX",
    _52
    "name": "testchatroom2",
    _52
    "description": "test",
    _52
    "membersonly": false,
    _52
    "allowinvites": false,
    _52
    "invite_need_confirm": true,
    _52
    "maxusers": 10000,
    _52
    "created": 1641289021898,
    _52
    "custom": "",
    _52
    "mute": false,
    _52
    "affiliations_count": 1,
    _52
    "affiliations": [
    _52
    {
    _52
    "owner": "user3"
    _52
    }
    _52
    ],
    _52
    "public": true
    _52
    }
    _52
    ],
    _52
    "duration": 0,
    _52
    "entities": [],
    _52
    "organization": "XXXX",
    _52
    "timestamp": 1642064417048,
    _52
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/XXXX%2CXXXX"
    _52
    }

    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


    _1
    PUT https://{host}/{org_name}/{app_name}/chatrooms/{chatroom_id}

    Path parameter

    ParameterTypeDescriptionRequired
    chatroom_idStringThe 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

    ParameterTypeDescriptionRequired
    Content-TypeStringapplication/jsonYes
    AcceptStringapplication/jsonYes
    AuthorizationStringThe 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:

    FieldTypeDescriptionRequired
    nameStringThe chat room name.No
    descriptionStringThe chat room description.No
    maxusersNumberThe 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:

    FieldTypeDescription
    groupnameBoolWhether the chat room name is successfully changed.
  • true: Success
  • false: Failure
  • descriptionBoolWhether the chat room description is successfully modified.
  • true: Success
  • false: Failure
  • maxusersBoolWhether the maximum number of members that can join the chat room is successfully changed.
  • true: Success
  • false: 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, and maxusers are passed in the request body, the request fails and the error code 400 is returned.

    Example

    Request example


    _5
    curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' -d '{
    _5
    "name": "testchatroom",
    _5
    "description": "test",
    _5
    "maxusers": 300,
    _5
    }' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX'

    Response example


    _7
    {
    _7
    "data": {
    _7
    "description": true,
    _7
    "maxusers": true,
    _7
    "groupname": true
    _7
    }
    _7
    }

    Deleting the specified chat room

    Deletes the specified chat room. If the specified chat room does not exist, an error returns.

    HTTP request


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

    Path parameter

    ParameterTypeDescriptionRequired
    chatroom_idStringThe 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

    ParameterTypeDescriptionRequired
    AcceptStringapplication/jsonYes
    AuthorizationStringThe 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:

    FieldTypeDescription
    successBoolWhether the chat room is successfully deleted.
  • true: Success
  • false: Failure
  • idStringThe 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


    _2
    # Replace <YourAppToken> with the app token generated in your server.
    _2
    curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX'

    Response example


    _14
    {
    _14
    "action": "delete",
    _14
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _14
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/XXXX",
    _14
    "entities": [],
    _14
    "data": {
    _14
    "success": true,
    _14
    "id": "66211860774913"
    _14
    },
    _14
    "timestamp": 1542545100474,
    _14
    "duration": 0,
    _14
    "organization": "XXXX",
    _14
    "applicationName": "XXXX"
    _14
    }

    Retrieving a chat room announcement

    Retrieves the announcement text for the specified chat room.

    HTTP request


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

    Path parameter

    ParameterTypeRequiredDescription
    chatroom_idStringYesThe 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

    ParameterTypeRequiredDescription
    Content-TypeStringYesSet to application/json.
    AcceptStringYesapplication/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

    The response body contains the following fields:

    ParameterTypeDescription
    data.announcementStringThe announcement text of the specified chat room.

    Example

    Request example


    _1
    curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourToken> ' 'http://XXXX/XXXX/XXXX/chatrooms/XXXX/announcement'

    Response example


    _13
    {
    _13
    "action": "get",
    _13
    "application": "52XXXXf0",
    _13
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/12XXXX11/announcement",
    _13
    "entities": [],
    _13
    "data": {
    _13
    "announcement" : "Chat room announcement text"
    _13
    },
    _13
    "timestamp": 1542363546590,
    _13
    "duration": 0,
    _13
    "organization": "XXXX",
    _13
    "applicationName": "testapp"
    _13
    }

    Modifying the announce of a chat room

    Modifies the announcement text of the specified chat room. The length cannot exceed 512 characters.

    HTTP request


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

    Path parameter

    ParameterTypeDescriptionRequired
    chatroom_idStringThe 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

    ParameterTypeRequiredDescription
    Content-TypeStringYesSet to application/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

    ParameterTypeRequiredDescription
    announcementStringYesThe 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:

    ParameterTypeDescription
    data.idStringThe chat room ID.
    data.resultBooleanWhether 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


    _1
    curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken> ' 'http://XXXX/XXXX/XXXX/chatrooms/12XXXX11/announcement' -d '{"announcement" : "chat room announcement"}'

    Response example


    _14
    {
    _14
    "action": "post",
    _14
    "application": "52XXXXf0",
    _14
    "uri": "http://XXXX/XXXX/XXXX/chatrooms/12XXXX11/announcement",
    _14
    "entities": [],
    _14
    "data": {
    _14
    "id": "12XXXX11",
    _14
    "result": true
    _14
    },
    _14
    "timestamp": 1594808604236,
    _14
    "duration": 0,
    _14
    "organization": "XXXX",
    _14
    "applicationName": "testapp"
    _14
    }

    Status codes

    For details, see HTTP Status Codes.

    vundefined