Contact management refers to operations such as adding and removing contacts, and adding and removing users from the block list.
This page shows how to call the Agora Chat RESTful APIs to create and manage contacts.
Before calling the following methods, make sure you understand the call frequency limit as 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 Chat 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 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 |
Array | The actual requested data. |
entities.uuid |
String | The user's UUID. The unique internal identifier generated by the Agora Chat service. You can safely ignore this parameter. |
entities.type |
String | The Object type. You can safely ignore this parameter. |
entities.created |
String | The Unix timestamp (ms) when the user is registered. |
entities.modified |
String | The Unix timestamp (ms) when the user attribute is last modified. |
entities.username |
String | The username. The unique account the user is logged in with. |
entities.activated |
Boolean | Whether the user is active:
|
timestamp |
Number | The Unix timestamp (ms) when the user is registered. |
duration |
Number | The time duration (ms) from sending the HTTP request to receiving the response. |
The Agora Chat RESTful API requires 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 in to the chat system. The Agora Chat RESTful API only supports authenticating users using app tokens. For details, see Authentication using App Token.
This method adds a user under the same App Key as contacts. The number of contacts supported differs by package version; the maximum number of contacts supported by the free version is 100. For details, see Limitations.
For each App Key, the call frequency limit of this method is 100 per second.
POST https://{host}/{org_name}/{app_name}/users/{owner_username}/contacts/users/{friend_username}
Parameter | Type | Description | Required |
---|---|---|---|
owner_username |
String | The username of the local user. | Yes |
friend_username |
String | The username to be added as a contact. | 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 admin, in the format of Bearer ${YourAppToken} , 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. For the fields and descriptions of the response body, see Common parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible causes.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/contacts/users/user2'
{
"path": "/users/4759aa70-XXXX-XXXX-925f-6fa0510823ba/contacts",
"uri": "https://XXXX/XXXX/XXXX/users/4759aa70-eba5-11e8-925f-6fa0510823ba/contacts",
"timestamp": 1542598913819,
"organization": "XXXX",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"entities": [
{
"uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
"type": "user",
"created": 1542356523769,
"modified": 1542597334500,
"username": "user2",
"activated": true,
}
],
"action": "post",
"duration": 63,
"applicationName": "XXXX"
}
This method removes the user from the contact list.
For each App Key, the call frequency limit of this method is 100 per second.
DELETE https://{host}/{org_name}/{app_name}/users/{owner_username}/contacts/users/{friend_username}
Parameter | Type | Description | Required |
---|---|---|---|
owner_username |
String | The username of the local user. | Yes |
friend_username |
String | The username to be removed from the contact list. | 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 admin, in the format of Bearer ${YourAppToken} , 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. For the fields and descriptions of the response body, see Common parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible causes.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/contacts/users/user2'
{
"path": "/users/4759aa70-XXXX-XXXX-925f-6fa0510823ba/contacts",
"uri": "https://XXXX/XXXX/XXXX/users/4759aa70-eba5-11e8-925f-6fa0510823ba/contacts",
"timestamp": 1542599266616,
"organization": "XXXX",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"entities": [
{
"uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
"type": "user",
"created": 1542356523769,
"modified": 1542597334500,
"username": "user2",
"activated": true,
}
],
"action": "delete",
"duration": 350,
"applicationName": "XXXX"
}
This method retrieves the local user's contact list.
For each App Key, the call frequency limit of this method is 100 per second.
GET https://{host}/{org_name}/{app_name}/users/{owner_username}/contacts/users
Parameter | Type | Description | Required |
---|---|---|---|
owner_username |
String | The username of the local user. | Yes |
For other fields and descriptions, see Common parameter.
Parameter | Type | Description | Required |
---|---|---|---|
Accept |
String | The parameter type. Set it as application/json . |
Yes |
Authorization |
String | The authentication token of the user or admin, in the format of Bearer ${YourAppToken} , 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 response body contains the following fields:
Parameter | Type | Description |
---|---|---|
data |
Array | The contact list data. |
count |
Number | The number of contacts. |
For other fields and descriptions, see Common parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible causes.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/contacts/users'
{
"uri": "http://XXXX/XXXX/XXXX/users/user1/contacts/users",
"timestamp": 1543819826513,
"entities": [],
"count": 2
"action": "get",
"data": [
"user3",
"user2"
],
"duration": 12
}
Adds the specified user or users to the block list. Once you add a user to the block list, you can no longer receive messages from that user. The maximum number of users in the block list for each user is 500.
For each App Key, the call frequency limit of this method is 50 per second.
POST https://{host}/{org_name}/{app_name}/users/{owner_username}/blocks/users
For the descriptions of the path parameters of this method, see Common parameter.
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 admin, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Yes |
The request body is a JSON object, which contains the following fields:
Field | Type | Description | Required |
---|---|---|---|
usernames |
An array of usernames | The usernames to be added to the block list, such as ["user1", "user2"]. | Yes |
If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
data |
Array | An array of usernames to add to the block list. |
For other fields and descriptions, see Common parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible causes.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' -d '{ "usernames": [ "user2" ] }' 'http://XXXX/XXXX/XXXX/users/user1/blocks/users'
{
"uri": "https://XXXX/XXXX/XXXX",
"timestamp": 1542600372046,
"organization": "XXXX",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"entities": [],
"action": "post",
"data": [
"user2"
],
"duration": 110,
"applicationName": "XXXX"
}
This method retrieves the current user's block list.
For each App Key, the call frequency limit of this method is 50 per second.
GET https://{host}/{org_name}/{app_name}/users/{owner_username}/blocks/users
Parameter | Type | Description | Required |
---|---|---|---|
owner_username |
String | The username of the local user. | 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 admin, in the format of Bearer ${YourAppToken} , 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 response body contains the following fields:
Parameter | Type | Description |
---|---|---|
data |
Array | An array of usernames in the block list. |
For other fields and descriptions, see Common parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible causes.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/blocks/users'
{
"uri": "http://XXXX/XXXX/XXXX/users/user1/blocks/users",
"timestamp": 1542599978751,
"entities": [],
"count": 1,
"action": "get",
"data": [
"user2"
],
"duration": 4
}
This method removes the specified user from the block list. After removing a user from the block list, that user resumes their previous relationship with the local user, as a contact or a regular chat user, and can send and receive messages with the local user.
For each App Key, the call frequency limit of this method is 50 per second.
DELETE https://{host}/{org_name}/{app_name}/users/{owner_username}/blocks/users/{blocked_username}
Parameter | Type | Description | Required |
---|---|---|---|
owner_username |
String | The username of the local user. | Yes |
blocked_username |
String | The username to be removed from the block list. | 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 admin, in the format of Bearer ${YourAppToken} , 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 is successful. For fields and descriptions of the response body, see Common parameter.
If the returned HTTP status code is not 200, the request fails. You can refer to Status codes(#code) for possible causes.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/XXXX/XXXX/users/user1/blocks/users/user2'
{
"path": "/users/4759aa70-XXXX-XXXX-925f-6fa0510823ba/blocks",
"uri": "https://XXXX/XXXX/XXXX/users/4759aa70-eba5-11e8-925f-6fa0510823ba/blocks",
"timestamp": 1542600712985,
"organization": "XXXX",
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
"entities": [
{
"uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
"type": "user",
"created": 1542356523769,
"modified": 1542597334500,
"username": "user2",
"activated": true,
}
],
"action": "delete",
"duration": 20,
"applicationName": "XXXX"
}
For details, see HTTP Status Codes.