Contact management
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 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.
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 Chat 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 the Chat 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 the Chat 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 URL. You can safely ignore this parameter. |
entities | JSON | The response entity. |
entities.uuid | String | The user's UUID. A unique internal identifier generated by the Chat service for the user in this request. This is used for generating the user token. |
entities.type | String | The type of the object. You can safely ignore this parameter. |
entities.created | Number | The Unix timestamp (ms) when the user is registered. |
entities.modified | Number | The Unix timestamp (ms) when the user information is last modified. |
entities.username | String | The username. The unique account the user is logged in with. |
entities.activated | Bool | Whether the user is active:true : The user is active.false : The user is in banned. |
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.
Adding a contact
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.
HTTP request
Path parameter
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.
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 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 |
HTTP response
Response body
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.
Example
Request example
Response example
Removing a contact
This method removes the user from the contact list.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
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.
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 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 |
HTTP response
Response body
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.
Example
Request example
Response example
Retrieving the contact list
This method retrieves the local user's contact list.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
owner_username | String | The username of the local user. | Yes |
For other fields and descriptions, see Common parameter.
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 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 |
HTTP response
Response body
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.
Example
Request example
Response example
Adding users to the block list
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.
HTTP request
Path parameter
For the descriptions of the path parameters of this method, see Common parameter.
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 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 |
Request body
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 |
HTTP response
Response body
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.
Example
Request example
Response example
Retrieving the block list
This method retrieves the current user's block list.
For each App Key, the call frequency limit of this method is 50 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
owner_username | String | The username of the local user. | 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 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 |
HTTP response
Response body
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.
Example
Request example
Response example
Removing a user from the block list
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.
HTTP request
Path parameter
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.
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 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 |
HTTP response
Response body
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.
Example
Request example
Response example
Status codes
For details, see HTTP Status Codes.