User system registration
This page shows how to call Chat RESTful APIs to create and manage the user system, including how to register, modify, delete, ban, and unban a user, get user information, and force a user to log out.
Before calling the following methods, make sure you understand the call frequency limit of the Chat RESTful APIs 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 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. To use a banned user account, you need to call the unban-user method to unban the account. |
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.
Registering a user
This method creates a user account.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | 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 |
---|---|---|---|
username | String | The unique login account of the user. The username must be 64 characters or less and cannot be empty. | Yes |
password | String | The user's login password. The length cannot exceed 64 characters. | Yes |
nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. The length cannot exceed 100 characters. The default value is null. This field is used to set the user nickname displayed in the message push, not the user nickname in the user attributes. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Field | Type | Description |
---|---|---|
entities.nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. This field is not the user nickname of the user attributes. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Registering multiple users
This method registers multiple users within one request.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters .
Request header
Parameter | Type | Description |
---|---|---|
Content-Type | String | application/json |
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. |
Request body
The request body is a JSON object, which contains the following fields:
Field | Type | Description | Required |
---|---|---|---|
username | String | The unique login account of the user. The username must be 64 characters or less and cannot be empty. | Yes |
password | String | The user's login password. The length cannot exceed 64 characters. | Yes |
nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. The length cannot exceed 100 characters. The default value is null. This field is used to set the user nickname displayed in the message push, not the user nickname in the user attributes. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Field | Type | Description |
---|---|---|
entities.nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. This field is not the user nickname of the user attributes. |
data | JSONArray | The details of the response. In this data array, the username and reason for the registration failure is displayed. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example 1
Registering 2 users:
Response example 1
Request example 2
If the request body contains a user3 that has previously been registered, the registration of user3 fails while those of user1 and user2 succeed. The failure is reported in the data
array of the response body.
Response example 2
Querying a user
This method queries the detailed information of the specified user.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | 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:
Field | Type | Description |
---|---|---|
entities.nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. This field is not the user nickname of the user attributes. |
count | Number | The number of users. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Querying multiple users
This method queries the information of multiple users in ascending order of their registration time.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Query parameters
Parameter | Type | Description | Required |
---|---|---|---|
limit | Number | The number of users whose information you want to query. The default value is 10 , and the value range is [1,100]. The user list is displayed in ascending order of their registration time by default. | No |
cursor | String | The cursor used for paginating the user lists. You do not need to set cursor at the first query. When the request succeeds, you can get the user list on the first page. You can also get the cursor from the response body, and pass the cursor in the URL of the next request, until there is no longer a cursor field in the response body, which means that all the users in the app have been queried. | No |
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | 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 |
---|---|---|
entities.nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. This field is not the user nickname of the user attributes. |
cursor | String | The cursor used for paginating the user lists. You do not need to set cursor at the first query. When the request succeeds, you can get the cursor from the response body, and pass this cursor in the URL of the next query, until there is no longer a cursor filed in the response body, which indicates that all the users in the app have been queried. |
count | Number | The number of users. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible reasons.
Example
Request example 1
Querying the information list of two users in ascending order of their registration time:
Response example 1
Return the information list of the 2 users:
Request example 2
Use the cursor
in response example 1 to query the user list on the next page in ascending order of their registration time. The number of users on this page is two:
Response example 2
Continue to return a list of information for two users:
Deleting a user
This method deletes the specified user. If the deleted user is the admin of a chat group or chat room, the group or chat room managed by that user is also deleted.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | 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 fields and descriptions of the response body, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Deleting multiple users
This method deletes all the users in the app. If the deleted users include group or chat room admins, the groups and chat rooms managed by those users are also deleted.
For each App Key, the call frequency limit of this method is 30 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters .
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | 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 Public parameter.
If the returned HTTP status code is not 200
, the request fails. You can refer to the Status code for possible reasons.
Example
Request example
Response example
Modifying the password
This method modifies the user password. You do not need to provide the original password.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | application/json | Yes |
Accept | String | 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 |
---|---|---|---|
newpassword | String | The new user login password. The length cannot exceed 64 characters. | Yes |
For other fields and detailed descriptions, see Common parameters.
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds. For fields and descriptions of the response body, see Common parametes.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Banning a user
This method disables a user account. The user goes offline immediately and is not able to log in until the ban is lifted.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | application/json | Yes |
Accept | String | 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 succeeds and the response body contains the following fields:
Field | Type | Description |
---|---|---|
entities.nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. This field is not the user nickname of the user attributes. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Unbanning a user
This method unbans a deactivated user account. After the ban is lifted, the user can log in to Chat.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | application/json | Yes |
Accept | String | 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:
Field | Type | Description |
---|---|---|
nickname | String | The nickname of the user displayed in the notification bar of the message push when the message is pushed. This field is not the user nickname of the user attributes. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Forcing a user offline
This method forcibly moves a user offline. The offline user must log in again to use the Chat service.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | application/json | Yes |
Accept | String | 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:
Field | Type | Description |
---|---|---|
data | JSON | The details of the response. |
data.result | Bool | The logout result, only displayed as true , which indicates that the user has been forced offline. |
For other fields and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Querying the online state of a user
This method queries whether a user is online.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | 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 | Description |
---|---|
username | The online state of a user, in the format of "username": "online state" . For example, if user1 is online, returns "user1": "online" . Otherwise, returns "user1": "offline" . |
For the parameters and detailed descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Querying the online state of multiple users
This method queries whether multiple users are online.
For each App Key, the call frequency limit of this method is 50 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | 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
Parameter | Type | Description |
---|---|---|
usernames | Array | The users whose online state you want to query. You can specify a maximum of 100 usernames at the same time. |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Description |
---|---|
username | The online state of a user, in the format of "username": "online state" . For example, if user1 is online, returns "user1": "online" . Otherwise, returns "user1": "offline" . |
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
This API does not check whether the specified usernames are valid. If the specified username does not exist, the state of this user is reported as offline.
Querying the number of offline messages
This method queries the number of offline messages a user has, and whether or not they have been delivered.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Required | Description |
---|---|---|---|
owner_username | String | Yes | The users whose number of offline messages you want to query. |
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | 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
Request body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Description |
---|---|
username | The number of offline messages a user has, whether or not they have been delivered, in the format of "username": "number of offline messages" . For example, if user1 does not have offline messages, returns "user1": "0" . |
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Querying the delivery state of an offline message
This method queries the delivery state of an offline message.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Required | Description |
---|---|---|---|
username | String | Yes | The user whose offline message's delivery states you want to query. |
msg_id | String | Yes | The message of which you want to query the delivery state. |
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | 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 | Description |
---|---|
msg_id | The delivery state of an offline message, in the format of "message id": "delivery state" . The delivery state contains: delivered : The offline message has been delivered to the user. undelivered : The offline message is temporarily stored at the server and has not been pulled from the server and delivered to the user. |
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Status codes
For details, see HTTP Status Codes.