Skip to main content

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 creator) that can join a chat room.No
ownerStringThe username of the chat room creator.Yes
membersJSONArrayThe members in the chat room. This parameter cannot be empty.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
cursorStringNoThe starting position of the data query. This parameter is only required when fetching pages.
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


_8
{
_8
"data": {
_8
"id": "66211860774913",
_8
"name": "test",
_8
"owner": "user1",
_8
"affiliations_count": 2
_8
}
_8
}

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

Path parameter

For the 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:

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


_2
# Replace <YourAppToken> with the app token generated in your server.
_2
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


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

    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. It cannot contain slashes or spaces that need to be replaced with "+".No
    descriptionStringThe chat room description. It cannot contain slashes or spaces that need to be replaced with "+".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