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
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 URI. You can safely ignore this parameter. |
entities | JSON | The response entity. |
data | JSON | The details of the response. |
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.
Retrieving group members
Retrieves the member list of the specified chat group with pagination.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
pagenum | Number | The number of page on which the member list is retrieved. | No |
pagesize | Number | The number of members displayed on each page. The default value is 10 and the maximum value is 100. | No |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | The parameter type. Set it as 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 data
field in the response body contains the following parameters.
Parameter | Type | Description |
---|---|---|
owner | String | The username of the group owner, for example, {"owner":"user1"} . |
member | String | The username of group members, for example, {"member":"user2"} . |
For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
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
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The parameter type. Set it as application/json . | Yes |
Accept | String | The parameter type. Set it as 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 data
field in the response body contains the following parameters.
Parameter | Type | Description |
---|---|---|
result | Boolean | Whether the user is successfully added to the chat group. |
groupid | String | The group ID. |
action | String | The request method. |
user | String | The username added to the chat group. |
For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
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
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The parameter type. Set it as application/json . | Yes |
Accept | String | The parameter type. Set it as 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
Parameter | Type | Description | Required |
---|---|---|---|
usernames | Array | The 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.
Parameter | Type | Description |
---|---|---|
newmembers | Array | The array of usernames that are added to the group. |
groupid | String | The group ID. |
action | String | The request method. |
For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
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
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | The parameter type. Set it as 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 data
field in the response body contains the following parameters.
Parameter | Type | Description |
---|---|---|
result | Boolean | Whether the user is successfully removed from the chat group. |
groupid | String | The group ID. |
action | String | The request method. |
user | String | The usernames removed from the chat group. |
For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
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
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
members | String | The 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
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | The parameter type. Set it as 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 data
field in the response body contains the following parameters.
Parameter | Type | Description |
---|---|---|
result | Boolean | Whether the user is successfully removed from the chat group. |
groupid | String | The group ID. |
reason | String | The reason why the users fail to be removed from the chat group. |
action | String | The request method. |
user | String | The usernames removed from the chat group. |
For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
Retrieving group admin list
Retrieves the list of the chat group admins.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The parameter type. Set it as 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 data
field in the response body contain the information of the chat group admins. For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
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
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The parameter type. Set it as application/json . | Yes |
Accept | String | The parameter type. Set it as 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
Parameter | Type | Description | Required |
---|---|---|---|
newadmin | String | The username be added as 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 usernames of the newly added chat group admins. For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
Removing a group admin
Removes the specified user from the chat group admin list.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | The parameter type. Set it as 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 data
field in the response body contains the following parameters.
Parameter | Type | Description |
---|---|---|
result | Boolean | Whether the group admin is successfully demoted to a regular group member:
|
oldadmin | String | The ID of the group admin demoted to a regular group member. |
For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
Transferring group ownership
Changes the group owner to another group member. Group owners possess all group privileges.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
group_id | String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The parameter type. Set it as application/json . | Yes |
Accept | String | The parameter type. Set it as 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
Parameter | Type | Description | Required |
---|---|---|---|
newowner | String | The 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.
Parameter | Type | Description |
---|---|---|
newowner | Boolean | Whether the user is successfully set as the chat group owner. true: Yes; false: No. |
For other fields and descriptions, see Public parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status code for possible causes.
Example
Request example
Response example
Status codes
For details, see HTTP Status Codes.