Group member management involves operations such as member creation and deletion. Agora 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 Agora Chat RESTful APIs. Before calling the following methods, ensure that you understand the call frequency limit described in Limitations.
The following table lists common request and response parameters of the Agora Chat RESTful APIs:
Parameter | Type | Description | Required |
---|---|---|---|
host |
String | The domain name assigned by the Agora 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 Agora 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 Agora Chat service. For how to get the app name, see Get the information of your project. | Yes |
username |
String | The username. The unique login account of the user. The username must be 64 characters or less and cannot be empty. The following character sets are supported:
|
Yes |
Parameter | Type | Description |
---|---|---|
action |
String | The request method. |
organization |
String | The unique identifier assigned to each company (organization) by the Agora Chat service. This is the same as org_name . |
application |
String | A unique internal ID assigned to each app by the Agora Chat service. You can safely ignore this parameter. |
applicationName |
String | The unique identifier assigned to each app by the Agora 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 URL. 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. |
Agora 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:
Authorization: Bearer ${YourAppToken}
In order to improve the security of the project, Agora uses a token (dynamic key) to authenticate users before they log into the chat system. The Agora Chat RESTful API only supports authenticating users using app tokens. For details, see Authentication using App Token.
Retrieves the member list of the specified chat group with pagination.
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users
// Gets the member list of the group with pagination.
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users?pagenum={N}&pagesize={N}
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.
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 |
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.
curl -X GET -H 'Accept: application/json' 'http://XXXX/XXXX/XXXX/chatgroups/10130212061185/users?pagenum=2&pagesize=2' -H 'Authorization: Bearer <YourAppToken>'
{
"action": "get",
"application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
"params": {
"pagesize": [
"2"
],
"pagenum": [
"2"
]
},
"uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/users",
"entities": [],
"data": [
{
"member": "user1"
},
{
"member": "user2"
}
],
"timestamp": 1489074511416,
"duration": 0,
"organization": "XXXX",
"applicationName": "XXXX",
"count": 2
}
Adds the specified user to the chat group. If the user is already a member of the chat group, an error is returned.
POST https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}
Parameter | Type | Description | Required |
---|---|---|---|
group_id |
String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common 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 |
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.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user4'
{
"action": "post",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user4",
"entities": [],
"data": {
"result": true,
"groupid": "66016455491585",
"action": "add_member",
"user": "user4"
},
"timestamp": 1542364958405,
"duration": 0,
"organization": "XXXX",
"applicationName": "XXXX"
}
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.
POST https://{host}/{org_name}/{app_name}/chatgroups/{chatgroupid}/users
Parameter | Type | Description | Required |
---|---|---|---|
group_id |
String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common 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 |
Parameter | Type | Description | Required |
---|---|---|---|
usernames |
Array | The usernames added to the chat group. | Yes |
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.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' -d '{
"usernames": [
"user4","user5"
]
}' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users'
{
"action": "post",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users",
"entities": [],
"data": {
"newmembers": [
"user5",
"user4"
],
"groupid": "66016455491585",
"action": "add_member"
},
"timestamp": 1542365557942,
"duration": 0,
"organization": "XXXX",
"applicationName": "XXXX"
}
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.
DELETE https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}
Parameter | Type | Description | Required |
---|---|---|---|
group_id |
String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
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 |
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.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user3'
{
"action": "delete",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/user3",
"entities": [],
"data": {
"result": true,
"action": "remove_member",
"user": "user3",
"groupid": "66016455491585"
},
"timestamp": 1542365943067,
"duration": 0,
"organization": "XXXX",
"applicationName": "XXXX"
}
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.
DELETE https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/users/{memebers}
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.
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 |
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.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66016455491585/users/ttestuser0015981,user2,user3'
{
"action": "delete",
"application": "9b848cf0-XXXX-XXXX-b5b8-0f74e8e740f7",
"uri": "https://XXXX/XXXX/XXXX",
"entities": [],
"data": [{
"result": false,
"action": "remove_member",
"reason": "user ttestuser0015981 doesn't exist.",
"user": "user1"
"groupid": "1433492852257879"
},
{
"result": true,
"action": "remove_member",
"user": "user2",
"groupid": "1433492852257879"
},
{
"result": true,
"action": "remove_member",
"user": "user3",
"groupid": "1433492852257879"
}],
"timestamp": 1433492935318,
"duration": 84,
"organization": "XXXX",
"applicationName": "XXXX"
}
Retrieves the list of the chat group admins.
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin
Parameter | Type | Description | Required |
---|---|---|---|
group_id |
String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
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 |
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.
curl -X GET HTTP://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin -H 'Authorization: Bearer <YourAppToken>'
{
"action": "get",
"application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
"uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin",
"entities": [],
"data": ["user1"],
"timestamp": 1489073361210,
"duration": 0,
"organization": "XXXX",
"applicationName": "XXXX",
"count": 1
}
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.
POST https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin
Parameter | Type | Description | Required |
---|---|---|---|
group_id |
String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common 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 |
Parameter | Type | Description | Required |
---|---|---|---|
newadmin |
String | The username be added as the chat group admin. | Yes |
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.
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>'
{
"action": "get",
"application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
"uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin",
"entities": [],
"data": ["user1"],
"timestamp": 1489073361210,
"duration": 0,
"organization": "XXXX",
"applicationName": "XXXX",
"count": 1
}
Removes the specified user from the chat group admin list.
DELETE https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin
Parameter | Type | Description | Required |
---|---|---|---|
group_id |
String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common parameters.
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 |
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.
curl -X DELETE -H 'Accept: application/json' 'http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin/user1' -H 'Authorization: Bearer <YourAppToken>'
{
"action": "delete",
"application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
"uri": "http://XXXX/XXXX/XXXX/chatgroups/10130212061185/admin/user1",
"entities": [],
"data": {
"result": "success",
"oldadmin": "user1"
},
"timestamp": 1489073432732,
"duration": 1,
"organization": "XXXX",
"applicationName": "XXXX"
}
Changes the group owner to another group member. Group owners possess all group privileges.
PUT https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/admin
Parameter | Type | Description | Required |
---|---|---|---|
group_id |
String | The group ID. | Yes |
For other parameters and detailed descriptions, see Common 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 |
Parameter | Type | Description | Required |
---|---|---|---|
newowner |
String | The username of the new group owner. | Yes |
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.
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'
{
"action": "put",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"uri": "http://XXXX/XXXX/XXXX/chatgroups/66016455491585",
"entities": [],
"data": {
"newowner": true
},
"timestamp": 1542537813420,
"duration": 0,
"organization": "XXXX",
"applicationName": "XXXX"
}
For details, see HTTP Status Codes.