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 |
Query parameter
Parameter | Type | Description | Required |
---|---|---|---|
pagenum | Number | The current page number. The query starts from the first page by default. | No |
pagesize | Number | The 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
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 a group admin or regular group member, for example, {"member":"user2"} . |
count | String | The number of group members retrieved at this call of this API. |
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
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 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
Response example
Adding multiple users to the chat group
Adds multiple users to the specified chat group. You can add a maximum of 60 users into a chat group each 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 to add to the chat group. You can pass in a maximum of 60 usernames each time. | 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 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
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 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
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 each 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 to 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 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
Response example
Setting custom attributes of a group member
Sets the custom attributes of a group member, such as adding a nickname or avatar. Each custom attribute should be in key-value format.
The group owner can modify custom attributes of all group members and other members in the group can only modify their own custom attributes.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
username | String | The user ID of a group member for which custom attributes are set. | 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 ${YourAppToken} , where Bearer is a fixed character, followed by a space and then the obtained token value. | Yes |
Response body
Parameter | Type | Description |
---|---|---|
metaData | JSON | Custom attributes of a group member to set. Each attribute is represented as a key-value pair:
|
HTTP response
Response body
If the returned HTTP status code is 200, the request succeeds and the response body contains the following parameters.
Field | Type | Description |
---|---|---|
data | JSON | Custom attributes of a group member that are set. |
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
Response example
Retrieving all custom attributes of a group member
Retrieves all custom attributes of a group member.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
username | String | The user ID of a group member whose custom attributes are to be retrieved. | 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 ${YourAppToken} , 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 will contain the following parameters.
Field | Type | Description |
---|---|---|
data | JSON | All custom attributes of a group member that are retrieved. |
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
Response example
Retrieving custom attributes of multiple group members by attribute key
Retrieves custom attributes of multiple group members by attribute key. You can retrieve custom attributes of at most 10 group members each time.
HTTP request
Path parameter
For the 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 ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. | Yes |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
targets | JSON Array | The user IDs of group members whose custom attributes are to be retrieved. You can pass in at most 10 user IDs. | Yes |
properties | JSON Array | The array of keys of custom attributes to retrieve. If you pass in an empty string or no value to the parameter, all custom attributes of the group members will be returned. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200, the request succeeds and the response body will contain the following parameters.
Field | Type | Description |
---|---|---|
data | JSON | The custom attributes of the group members that are retrieved. As shown in the following response example, test1 and test2 are user IDs of group members to which the retrieved custom attributes belong. |
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
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 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
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 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.
Parameter | Type | Description |
---|---|---|
data | String | The user IDs promoted to group admins. |
count | Number | The 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
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 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
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 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
Response example
Status codes
For details, see HTTP Status Codes.