Skip to main content

Manage group members

Group member management involves operations such as member creation and deletion. Chat provides multiple APIs for adding and retrieving group members, adding a group administrator, and transferring the group owner.

This page shows how to manage group members 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

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 URI. You can safely ignore this parameter.
entities JSONThe response entity.
dataJSONThe details of the response.
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.

Retrieving group members

Retrieves the member list of the specified chat group with pagination.

HTTP request


_4
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users
_4
_4
// Gets the member list of the group with pagination.
_4
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users?pagenum={N}&pagesize={N}

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes

Query parameter

ParameterTypeDescriptionRequired
pagenumNumberThe current page number. The query starts from the first page by default.No
pagesizeNumberThe number of members to retrieve per page. The default value is 10. The value range is [1,100].No

For other parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeDescriptionRequired
AcceptStringThe parameter type. Set it as application/json.Yes
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 data field in the response body contains the following parameters.

ParameterTypeDescription
ownerStringThe username of the group owner, for example, {"owner":"user1"}.
memberStringThe username of group members, for example, {"member":"user2"}.

For other fields and descriptions, see Common parameters.

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

Example

Request example


_1
curl -X GET -H 'Accept: application/json' 'http://XXXX/XXXX/XXXX/chatgroups/10130212061185/users?pagenum=2&pagesize=2' -H 'Authorization: Bearer <YourAppToken>'

Response example


_27
{
_27
"action": "get",
_27
"application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
_27
"params": {
_27
"pagesize": [
_27
"2"
_27
],
_27
"pagenum": [
_27
"2"
_27
]
_27
},
_27
"uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/users",
_27
"entities": [],
_27
"data": [
_27
{
_27
"member": "user1"
_27
},
_27
{
_27
"member": "user2"
_27
}
_27
],
_27
"timestamp": 1489074511416,
_27
"duration": 0,
_27
"organization": "XXXX",
_27
"applicationName": "XXXX",
_27
"count": 2
_27
}

Adding a user to the chat group

Adds the specified user to the chat group. If the user is already a member of the chat group, an error is returned.

HTTP request


_1
POST https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes

For other parameters and detailed descriptions, see Common parameters.

Request parameters

ParameterTypeDescriptionRequired
Content-TypeStringThe parameter type. Set it as application/json.Yes
AcceptStringThe parameter type. Set it as application/json.Yes
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 data field in the response body contains the following parameters.

ParameterTypeDescription
resultBooleanWhether the user is successfully added to the chat group.
  • true: Yes.
  • false: No.
  • groupidStringThe group ID.
    actionStringThe request method.
    userStringThe username added to the chat group.

    For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _1
    curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user4'

    Response example


    _16
    {
    _16
    "action": "post",
    _16
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _16
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user4",
    _16
    "entities": [],
    _16
    "data": {
    _16
    "result": true,
    _16
    "groupid": "66016455491585",
    _16
    "action": "add_member",
    _16
    "user": "user4"
    _16
    },
    _16
    "timestamp": 1542364958405,
    _16
    "duration": 0,
    _16
    "organization": "XXXX",
    _16
    "applicationName": "XXXX"
    _16
    }

    Adding multiple users to the chat group

    Adds mutiple users to the specified chat group. You can add a maximum of 60 users into a chat group at one time. If the users are already members of the chat group, an error is returned in the response body.

    HTTP request


    _1
    POST https://{host}/{org_name}/{app_name}/chatgroups/{chatgroupid}/users

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe group ID.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe parameter type. Set it as application/json.Yes
    AcceptStringThe parameter type. Set it as application/json.Yes
    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

    ParameterTypeDescriptionRequired
    usernamesArrayThe usernames added to the chat group.Yes

    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
    newmembersArrayThe array of usernames that are added to the group.
    groupidStringThe group ID.
    actionStringThe request method.

    For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _5
    curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' -d '{
    _5
    "usernames": [
    _5
    "user4","user5"
    _5
    ]
    _5
    }' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users'

    Response example


    _18
    {
    _18
    "action": "post",
    _18
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _18
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users",
    _18
    "entities": [],
    _18
    "data": {
    _18
    "newmembers": [
    _18
    "user5",
    _18
    "user4"
    _18
    ],
    _18
    "groupid": "66016455491585",
    _18
    "action": "add_member"
    _18
    },
    _18
    "timestamp": 1542365557942,
    _18
    "duration": 0,
    _18
    "organization": "XXXX",
    _18
    "applicationName": "XXXX"
    _18
    }

    Removing a chat group member

    Removes the specified user from the chat group. If the specified user is not in the chat group, an error is returned.

    Once a member is removed from a chat group, they are also removed from all the threads they have joined in this chat group.

    HTTP request


    _1
    DELETE https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe group ID.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringThe parameter type. Set it as application/json.Yes
    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 data field in the response body contains the following parameters.

    ParameterTypeDescription
    resultBooleanWhether the user is successfully removed from the chat group.
  • true: Yes.
  • false: No.
  • groupidStringThe group ID.
    actionStringThe request method.
    userStringThe usernames removed from the chat group.

    For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _1
    curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user3'

    Response example


    _16
    {
    _16
    "action": "delete",
    _16
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _16
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user3",
    _16
    "entities": [],
    _16
    "data": {
    _16
    "result": true,
    _16
    "action": "remove_member",
    _16
    "user": "user3",
    _16
    "groupid": "66016455491585"
    _16
    },
    _16
    "timestamp": 1542365943067,
    _16
    "duration": 0,
    _16
    "organization": "XXXX",
    _16
    "applicationName": "XXXX"
    _16
    }

    Removing multiple group members

    Removes multiple users from the chat group. You can remove a maximum of 60 members from the chat group at one time. If the specified users are not in the group, an error is returned.

    Once a member is removed from a chat group, they are also removed from all the threads they have joined in this chat group.

    HTTP request


    _1
    DELETE https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users/{members}

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe group ID.Yes
    membersStringThe usernames of group members separated by the comma (,). For example, user1, user2.Yes

    For the descriptions of other path parameters, see Common Parameters.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringThe parameter type. Set it as application/json.Yes
    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 to and the data field in the response body contains the following parameters.

    ParameterTypeDescription
    resultBooleanWhether the user is successfully removed from the chat group.
  • true: Yes.
  • false: No.
  • groupidStringThe group ID.
    reasonStringThe reason why the users fail to be removed from the chat group.
    actionStringThe request method.
    userStringThe usernames removed from the chat group.

    For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _1
    curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/ttestuser0015981,user2,user3'

    Response example


    _29
    {
    _29
    "action": "delete",
    _29
    "application": "9b848cf0-XXXX-XXXX-b5b8-0f74e8e740f7",
    _29
    "uri": "https://XXXX/XXXX/XXXX",
    _29
    "entities": [],
    _29
    "data": [{
    _29
    "result": false,
    _29
    "action": "remove_member",
    _29
    "reason": "user ttestuser0015981 doesn't exist.",
    _29
    "user": "user1"
    _29
    "groupid": "1433492852257879"
    _29
    },
    _29
    {
    _29
    "result": true,
    _29
    "action": "remove_member",
    _29
    "user": "user2",
    _29
    "groupid": "1433492852257879"
    _29
    },
    _29
    {
    _29
    "result": true,
    _29
    "action": "remove_member",
    _29
    "user": "user3",
    _29
    "groupid": "1433492852257879"
    _29
    }],
    _29
    "timestamp": 1433492935318,
    _29
    "duration": 84,
    _29
    "organization": "XXXX",
    _29
    "applicationName": "XXXX"
    _29
    }

    Retrieving group admin list

    Retrieves the list of the chat group admins.

    HTTP request


    _1
    GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe group ID.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe parameter type. Set it as application/json.Yes
    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 data field in the response body contain the information of the chat group admins. For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _1
    curl -X GET HTTP://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin -H 'Authorization: Bearer <YourAppToken>'

    Response example


    _12
    {
    _12
    "action": "get",
    _12
    "application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
    _12
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin",
    _12
    "entities": [],
    _12
    "data": ["user1"],
    _12
    "timestamp": 1489073361210,
    _12
    "duration": 0,
    _12
    "organization": "XXXX",
    _12
    "applicationName": "XXXX",
    _12
    "count": 1
    _12
    }

    Adding a group admin

    Adds a regular group member to the group admin list. A chat group admin has the privilege to manage the chat group block list and mute chat group members. You can add a maximum of 99 chat group admins.

    HTTP request


    _1
    POST https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe group ID.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe parameter type. Set it as application/json.Yes
    AcceptStringThe parameter type. Set it as application/json.Yes
    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

    ParameterTypeDescriptionRequired
    newadminStringThe username of the chat group admin.Yes

    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
    dataStringThe user IDs promoted to group admins.
    countNumberThe number of users to be promoted as group admins.

    For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _1
    curl -X POST -H 'Content-type: application/json' -H 'Accept: application/json' 'http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin' -d '{"newadmin":"user1"}' -H 'Authorization: Bearer <YourAppToken>'

    Response example


    _12
    {
    _12
    "action": "get",
    _12
    "application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
    _12
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin",
    _12
    "entities": [],
    _12
    "data": ["user1"],
    _12
    "timestamp": 1489073361210,
    _12
    "duration": 0,
    _12
    "organization": "XXXX",
    _12
    "applicationName": "XXXX",
    _12
    "count": 1
    _12
    }

    Removing a group admin

    Removes the specified user from the chat group admin list.

    HTTP request


    _1
    DELETE https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe group ID.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    AcceptStringThe parameter type. Set it as application/json.Yes
    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 data field in the response body contains the following parameters.

    ParameterTypeDescription
    resultBooleanWhether the group admin is successfully demoted to a regular group member:
    • true: Yes.
    • false: No.
    oldadminStringThe ID of the group admin demoted to a regular group member.

    For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _1
    curl -X DELETE -H 'Accept: application/json' 'http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin/user1' -H 'Authorization: Bearer <YourAppToken>'

    Response example


    _14
    {
    _14
    "action": "delete",
    _14
    "application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
    _14
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin/user1",
    _14
    "entities": [],
    _14
    "data": {
    _14
    "result": "success",
    _14
    "oldadmin": "user1"
    _14
    },
    _14
    "timestamp": 1489073432732,
    _14
    "duration": 1,
    _14
    "organization": "XXXX",
    _14
    "applicationName": "XXXX"
    _14
    }

    Transferring group ownership

    Changes the group owner to another group member. Group owners possess all group privileges.

    HTTP request


    _1
    PUT https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin

    Path parameter

    ParameterTypeDescriptionRequired
    group_idStringThe group ID.Yes

    For other parameters and detailed descriptions, see Common parameters.

    Request header

    ParameterTypeDescriptionRequired
    Content-TypeStringThe parameter type. Set it as application/json.Yes
    AcceptStringThe parameter type. Set it as application/json.Yes
    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

    ParameterTypeDescriptionRequired
    newownerStringThe username of the new group owner.Yes

    HTTP response

    Response body

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

    ParameterTypeDescription
    newownerBooleanWhether the user is successfully set as the chat group owner. true: Yes; false: No.

    For other fields and descriptions, see Common parameters.

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

    Example

    Request example


    _1
    curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' -d '{ "newowner": "user2" }' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585'

    Response example


    _13
    {
    _13
    "action": "put",
    _13
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _13
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585",
    _13
    "entities": [],
    _13
    "data": {
    _13
    "newowner": true
    _13
    },
    _13
    "timestamp": 1542537813420,
    _13
    "duration": 0,
    _13
    "organization": "XXXX",
    _13
    "applicationName": "XXXX"
    _13
    }

    Status codes

    For details, see HTTP Status Codes.

    vundefined