# User system registration (/en/api-reference/api-ref/im/user-system-registration)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

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](./limitations#call-limit-of-server-sides).

## Common parameters [#common-parameters]

The following table lists common request and response parameters of the Chat RESTful APIs:

### Request parameters [#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](/en/realtime-media/im/get-started/enable#get-the-information-of-the-agora-chat-project).                                                                                                                                                                                                                                                                                                                | Yes      |
| `app_id`   | String | The unique identifier automatically assigned to each project by Agora                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | 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:* 26 lowercase English letters (a-z)
* 10 numbers (0-9)
* "\_", "-", "."<CalloutContainer type="info">
  <CalloutDescription>
    Do not use any of the 26 uppercase English letters (A-Z). Ensure that each `username` under the same App ID is unique. Do not set this parameter as a UUID, email address, phone number, or other sensitive information.
  </CalloutDescription>
</CalloutContainer> | Yes      |

### Response parameters [#response-parameters]

| Parameter            | Type       | Description                                                                                                                                                                               |
| :------------------- | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `action`             | String     | The request method.                                                                                                                                                                       |
| `organization`       | String     | The unique identifier assigned to each company (organization) by the Chat service.                                                                                                        |
| `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 .                                                                                                                          |
| `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 Array | 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 banned. To use a banned user account, you need to call the [unban-user](#unban) 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 [#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:

```html
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. Chat RESTful APIs only support authenticating users using app tokens. For details, see [Authentication using App Token](/en/realtime-media/im/build/secure-access-and-authentication/authentication).

## Registering a user [#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 [#http-request]

```html
POST https://{host}/app-id/{app_id}/users
```

#### Path parameter [#path-parameter]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#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 [#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 bytes or less and cannot be empty. | Yes      |

### HTTP response [#http-response]

#### Response body [#response-body]

If the returned HTTP status code is `200`, the request succeeds. For fields and detailed descriptions, see [Common parameters](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example]

#### Request example [#request-example]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization:Bearer {YourAppToken}' -i "https://XXXX/app-id/XXXX/users" -d '
    {
      "username": "user1"
    }'
```

#### Response example [#response-example]

```json
{
    "action": "post",
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    "path": "/users",
    "uri": "https://a1.agora.com/XXXX/XXXX/users",
    "entities": [
        {
            "uuid": "0ffe2d80-XXXX-XXXX-8d66-279e3e1c214b",
            "type": "user",
            "created": 1542795196504,
            "modified": 1542795196504,
            "username": "user1",
            "activated": true,
        }
    ],
    "timestamp": 1542795196515,
    "duration": 0,
    "organization": "XXXX",
    "applicationName": "XXXX"
}
```

## Registering multiple users [#registering-multiple-users]

This method registers multiple users within one request. You can pass a maximum of 60 user IDs in a single request.

For each App Key, the call frequency limit of this method is 100 per second.

### HTTP request [#http-request-1]

```html
POST https://{host}/app-id/{app_id}/users
```

#### Path parameter [#path-parameter-1]

For the parameters and detailed descriptions, see [Common parameters ](#param).

#### Request header [#request-header-1]

| 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 [#request-body-1]

The request body is a JSONArray object, which contains the following fields:

| Field      | Type   | Description                                                                                                                         | Required |
| :--------- | :----- | :---------------------------------------------------------------------------------------------------------------------------------- | :------- |
| `username` | String | The unique user ID of the user. The user ID must be 64 characters or less and cannot be empty. You can pass in at most 60 user IDs. | Yes      |

### HTTP response [#http-response-1]

#### Response body [#response-body-1]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

| Field  | Type      | Description                                                                                                            |
| :----- | :-------- | :--------------------------------------------------------------------------------------------------------------------- |
| `data` | JSONArray | The details of the response. In this `data` array, the username and reason for the registration failure are displayed. |

For other fields and detailed descriptions, see [Common parameters](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-1]

#### Request example 1 [#request-example-1]

Registering 2 users:

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X POST -H 'Content-Type: application/json' -H 'Authorization:Bearer {YourAppToken}' -i "https://XXXX/app-id/XXXX/users" -d '[
    {
        "username":"user1"
    },
    {
        "username":"user2"
    }
]'
```

#### Response example 1 [#response-example-1]

```json
{
    "action": "post",
    "application": "22bcffa0-XXXX-XXXX-9df8-516f6df68c6d",
    "path": "/users",
    "uri": "https://XXXX/app-id/XXXX/users",
    "entities": [
        {
            "uuid": "278b5e60-XXXX-XXXX-8f9b-d5d83ebec806",
            "type": "user",
            "created": 1541587920710,
            "modified": 1541587920710,
            "username": "user1",
            "activated": true,
        },
        {
            "uuid": "278bac80-XXXX-XXXX-b192-73e4cd5078a5",
            "type": "user",
            "created": 1541587920712,
            "modified": 1541587920712,
            "username": "user2",
            "activated": true,
        }
    ],
    "timestamp": 1541587920714,
    "data": [],
    "duration": 0,
    "organization": "XXXX",
    "applicationName": "XXXX"
}
```

#### Request example 2 [#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.

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X POST -H 'Content-Type: application/json' -H 'Authorization:Bearer {YourAppToken}' -i "https://XXXX/app-id/XXXX/users" -d '[
    {
        "username":"user1"
    },
    {
        "username":"user2"
    },
    {
        "username":"user3"
    }
]'
```

#### Response example 2 [#response-example-2]

```json
{
    "action": "post",
    "application": "22bcffa0-XXXX-XXXX-9df8-516f6df68c6d",
    "path": "/users",
    "uri": "https://XXXX/app-id/XXXX/users",
    "entities": [
        {
            "uuid": "278b5e60-XXXX-XXXX-8f9b-d5d83ebec806",
            "type": "user",
            "created": 1541587920710,
            "modified": 1541587920710,
            "username": "user1",
            "activated": true,
        },
        {
            "uuid": "278bac80-XXXX-XXXX-b192-73e4cd5078a5",
            "type": "user",
            "created": 1541587920712,
            "modified": 1541587920712,
            "username": "user2",
            "activated": true,
        }
    ],
    "timestamp": 1541587920714,
    "data": [
        {
            "username": "user3",
            "registerUserFailReason": "the user3 already exists"
        }
    ],
    "duration": 0,
    "organization": "XXXX",
    "applicationName": "XXXX"
}
```

## Querying a user [#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 [#http-request-2]

```html
GET https://{host}/app-id/{app_id}/users/{username}
```

#### Path parameter [#path-parameter-2]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-2]

| 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 [#http-response-2]

#### Response body [#response-body-2]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

| Field   | Type   | Description          |
| :------ | :----- | :------------------- |
| `count` | Number | The number of users. |

For other fields and detailed descriptions, see [Common parameters](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-2]

#### Request example [#request-example-3]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/XXXX'
```

#### Response example [#response-example-3]

```json
{
    "action": "get",
    "path": "/users",
    "uri": "http://XXXX/app-id/XXXX/users/XXXX",
    "entities": [
        {
            "uuid": "0ffe2d80-XXXX-XXXX-8d66-279e3e1c214b",
            "type": "user",
            "created": 1542795196504,
            "modified": 1542795196504,
            "username": "XXXX",
            "activated": true,
            "nickname": "testuser"
        }
    ],
    "timestamp": 1542798985011,
    "duration": 1,
    "count": 1
}
```

## Querying multiple users [#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 [#http-request-3]

```html
GET https://{host}/app-id/{app_id}/users?limit={N}&{cursor}
```

#### Path parameter [#path-parameter-3]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Query 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 [#request-header-3]

| 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 [#http-response-3]

#### Response body [#response-body-3]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

| Parameter | Type   | Description                                                                                                                                                                                                                                                                                                                                                          |
| :-------- | :----- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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` field 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](#param).

If the returned HTTP status code is not 200, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-3]

#### Request example 1 [#request-example-1-1]

Querying the information list of two users in ascending order of their registration time:

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users?limit=2'
```

#### Response example 1 [#response-example-1-1]

Return the information list of the 2 users:

```json
{
    "action": "get",
    "params": {
        "limit": ["2"]
    },
    "path": "/users",
    "uri": "http://XXXX/app-id/XXXX/users",
    "entities": [
        {
            "uuid": "ab90eff0-XXXX-XXXX-9174-8f161649a182",
            "type": "user",
            "created": 1542356511855,
            "modified": 1542356511855,
            "username": "XXXX",
            "activated": true,
            "nickname": "testuser1"
        },
        {
            "uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
            "type": "user",
            "created": 1542356523769,
            "modified": 1542356523769,
            "username": "user2",
            "activated": true,
            "nickname": "testuser2"
        }
    ],
    "timestamp": 1542558467056,
    "duration": 1,
    "cursor": "LTgzNDAxMjM3OToxTEFnNE9sNEVlaVQ0UEdhdmJNR2tB",
    "count": 2
}
```

#### Request example 2 [#request-example-2-1]

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:

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users?limit=2&cursor=LTgzNDAxMjM3OToxTEFnNE9sNEVlaVQ0UEdhdmJNR2tB'
```

#### Response example 2 [#response-example-2-1]

Continue to return a list of information for two users:

```json
{
    "action": "get",
    "params": {
        "cursor": ["LTgzNDAxMjM3OToxTEFnNE9sNEVlaVQ0UEdhdmJNR2tB"],
        "limit": ["2"]
    },
    "path": "/users",
    "uri": "http://XXXX/app-id/XXXX/users",
    "entities": [
        {
            "uuid": "fef7f250-XXXX-XXXX-ba39-0fed7dcc3cdd",
            "type": "user",
            "created": 1542361376245,
            "modified": 1542361376245,
            "username": "XXXX",
            "activated": true,
            "nickname": "testuser3"
        },
        {
            "uuid": "gufhj730-XXXX-XXXX-bc68-d8ij7dc3uyac",
            "type": "user",
            "created": 1542361376978,
            "modified": 1542361376978,
            "username": "XXXX",
            "activated": true,
            "nickname": "testuser4"
        }
    ],
    "timestamp": 1542559337702,
    "duration": 2,
    "count": 2
}
```

## Deleting a user [#deleting-a-user]

This method deletes the specified user. If the deleted user is the admin of a group or chat room, the group or chat room they manage is also deleted.

For each App Key, the call frequency limit of this method is 100 per second.

### HTTP request [#http-request-4]

```html
DELETE https://{host}/app-id/{app_id}/users/{username}
```

#### Path parameter [#path-parameter-4]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-4]

| 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 [#http-response-4]

#### Response body [#response-body-4]

If the returned HTTP status code is `200`, the request succeeds. For fields and descriptions of the response body, see [Common parameters](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-4]

#### Request example [#request-example-4]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/user1'
```

#### Response example [#response-example-4]

```json
{
    "action": "delete",
    "applicationName": "XXXX"
    "path": "/users",
    "uri": "https://XXXX/app-id/XXXX/users",
    "entities": [
        {
            "uuid": "ab90eff0-XXXX-XXXX-9174-8f161649a182",
            "type": "user",
            "created": 1542356511855,
            "modified": 1542356511855,
            "username": "XXXX",
            "activated": true,
            "nickname": "user1"
        }
    ],
    "timestamp": 1542559539776,
    "duration": 39,
    "organization": "XXXX",
    "applicationName": "XXXX"
}
```

## Deleting multiple users [#deleting-multiple-users]

This method deletes multiple users in the app in the chronological order of their creation. For the first request, the API deletes users, starting from the first created one. A maximum of 100 users can be deleted each time. It should be noted that this method specifies the number of users to delete, instead of which users to delete.

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 [#http-request-5]

```html
DELETE https://{host}/app-id/{app_id}/users?limit={N}&cursor={cursor}
```

#### Path parameter [#path-parameter-5]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Query parameter [#query-parameter]

| Parameter | Type   | Description                                                                                                                                                                                                                                                  | Required |
| :-------- | :----- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- |
| `limit`   | Number | The number of users to delete. The value range is \[1,100] with `10` as the default.                                                                                                                                                                         | No       |
| `cursor`  | String | The position where to start deleting users.  No cursor is required for the first request. For each subsequent request, the cursor is obtained from the body of response to the previous request. If the cursor is no longer returned, all users are deleted. | No       |

#### Request header [#request-header-5]

| 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 [#http-response-5]

#### Response body [#response-body-5]

If the returned HTTP status code is `200`, the request is successful. For fields and descriptions of the response body, see [Public parameter](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to the [Status code](#code) for possible reasons.

### Example [#example-5]

#### Request example [#request-example-5]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer ' 'https://XXXX/app-id/XXXX/users?limit=2'
```

#### Response example [#response-example-5]

```json
{
  "action": "delete",
  "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
  "params": {
    "limit": ["2"]
  },
  "path": "/users",
  "uri": "https://XXXX/XXXX/testapp/users",
  "entities": [
    {
      "uuid": "b2aade90-XXXX-XXXX-a974-f3368f82e4f1",
      "type": "user",
      "created": 1542356523769,
      "modified": 1542597334500,
      "username": "user2",
      "activated": true,
      "nickname": "testuser"
    },
    {
      "uuid": "b98ad170-XXXX-XXXX-XXXX-7f76daa76557",
      "type": "user",
      "created": 1542356535303,
      "modified": 1542356535303,
      "username": "user3",
      "activated": true,
      "nickname": "user3"
    }
  ],
  "timestamp": 1542867197779,
  "duration": 504,
  "organization": "XXXX",
  "applicationName": "testapp",
  "cursor": "LTgXXXXDNR"
}
```

## Modifying the password [#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 [#http-request-6]

```html
PUT https://{host}/app-id/{app_id}/users/{username}/password
```

#### Path parameter [#path-parameter-6]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-6]

| 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 [#request-body-2]

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 bytes. | Yes      |

For other fields and detailed descriptions, see [Common parameters](#param).

### HTTP response [#http-response-6]

#### Response body [#response-body-6]

If the returned HTTP status code is `200`, the request succeeds. For fields and descriptions of the response body, see [Common parametes](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-6]

#### Request example [#request-example-6]

```bash
# Replace {YourAppToken} with the app token you generated on the server, and {YourPassword} with the new password you set
curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' -d '{ "newpassword": "{YourPassword}" }' ' http://XXXX/app-id/XXXX/users/user1/password'
```

#### Response example [#response-example-6]

```json
{
    "action": "set user password",
    "timestamp": 1542595598924,
    "duration": 8
}
```

## Banning a user [#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 [#http-request-7]

```html
POST https://{host}/app-id/{app_id}/users/{username}/deactivate
```

#### Path parameter [#path-parameter-7]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-7]

| 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 [#http-response-7]

#### Response body [#response-body-7]

If the returned HTTP status code is `200`, the request is succeeds and the response body contains the following fields:

For fields and detailed descriptions, see [Common parameters](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-7]

#### Request example [#request-example-7]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/user1/deactivate'
```

#### Response example [#response-example-7]

```json
{
    "action": "Deactivate user",
    "entities": [
        {
            "uuid": "4759aa70-XXXX-XXXX-925f-6fa0510823ba",
            "type": "user",
            "created": 1542595573399,
            "modified": 1542597578147,
            "username": "XXXX",
            "activated": false,
            "nickname": "user"
        }
    ],
    "timestamp": 1542602157258,
    "duration": 12
}
```

## Unbanning a user [#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 [#http-request-8]

```html
POST https://{host}/app-id/{app_id}/users/{username}/activate
```

#### Path parameter [#path-parameter-8]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-8]

| 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 [#http-response-8]

#### Response body [#response-body-8]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

For fields and detailed descriptions, see [Common parameters](#param).

For other fields and detailed descriptions, see [Common parameters](#param).
If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-8]

#### Request example [#request-example-8]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/user1/activate'
```

#### Response example [#response-example-8]

```json
{
    "action": "activate user",
    "timestamp": 1542602404132,
    "duration": 9
}
```

<a id="unbanning-a-user"></a>

## Forcing a user offline [#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 [#http-request-9]

```html
GET https://{host}/app-id/{app_id}/users/{username}/disconnect
```

#### Path parameter [#path-parameter-9]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-9]

| 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 [#http-response-9]

#### Response body [#response-body-9]

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](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-9]

#### Request example [#request-example-9]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/XXXX/disconnect'
```

#### Response example [#response-example-9]

```json
{
    "uri": "http://XXXX/app-id/XXXX/users/XXXX/disconnect",
    "timestamp": 1642053735842,
    "organization": "1122161011178276",
    "application": "22bcffa0-XXXX-XXXX-9df8-516f6df68c6d",
    "entities": [],
    "action": "get",
    "data": {
        "result": true
    },
    "duration": 0,
    "applicationName": "XXXX"
}
```

## Querying the online state of a user [#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 [#http-request-10]

```html
GET https://{host}/app-id/{app_id}/users/{username}/status
```

#### Path parameter [#path-parameter-10]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-10]

| 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 [#http-response-10]

#### Response body [#response-body-10]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

| Parameter | Type | Description                                                                                                                                                                       |
| :-------- | :--- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data`    | JSON | 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](#param).

If the returned HTTP status code is not `200`, the request fails. You can refer to [Status codes](./http-status-codes) for possible reasons.

### Example [#example-10]

#### Request example [#request-example-10]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/user1/status'
```

#### Response example [#response-example-10]

```json
{
    "action": "get",
    "uri": "http://XXXX/app-id/XXXX/users/user1/status",
    "entities": [],
    "data": {
        "user1": "offline"
    },
    "timestamp": 1542601284531,
    "duration": 4,
    "count": 0
}
```

## Querying the online state of multiple users [#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 [#http-request-11]

```html
POST https://{host}/app-id/{app_id}/users/batch/status
```

#### Path parameter [#path-parameter-11]

For the parameters and detailed descriptions, see [Common parameters](#param).

#### Request header [#request-header-11]

| 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 [#request-body-3]

| 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 [#http-response-11]

#### Response body [#response-body-11]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

| Parameter | Type | Description                                                                                                                                                                       |
| :-------- | :--- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data`    | JSON | 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](./http-status-codes) for possible reasons.

### Example [#example-11]

#### Request example [#request-example-11]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X POST http://XXXX/app-id/XXXX/users/batch/status -H 'Authorization: Bearer {YourAppToken}' -H 'Content-Type: application/json' -d '{"usernames":["user1","user2"]}'
```

#### Response example [#response-example-11]

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.

```json
{
  "action": "get batch user status",
  "data": [
    {
      "user1": "offline"
      },
    {
      "user2": "offline"
      }
    ],
  "timestamp": 1552280231926,
  "duration": 4
}
```

## Querying the number of offline messages [#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 [#http-request-12]

```html
GET https://{host}/app-id/{app_id}/users/{owner_username}/offline_msg_count
```

#### Path parameter [#path-parameter-12]

|     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](#param).

#### Request header [#request-header-12]

| 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 [#http-response-12]

#### Request body [#request-body-4]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

| Parameter | Type | Description                                                                                                                                                                                                             |
| :-------- | :--- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data`    | JSON | The number of offline messages a user has, regardless of the delivery state, 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](./http-status-codes) for possible reasons.

### Example [#example-12]

#### Request example [#request-example-12]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/user1/offline_msg_count'
```

#### Response example [#response-example-12]

```json
{
  "action": "get",
  "uri": "http://XXXX/XXX/XXXX/users/XXX/offline_msg_count",
  "entities": [],
  "data": {
    "user1": 0
  },
  "timestamp": 1542601518137,
  "duration": 3,
  "count": 0
}
```

## Querying the delivery state of an offline message [#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 [#http-request-13]

```html
GET https://{host}/app-id/{app_id}/users/{username}/offline_msg_status/{msg_id}
```

#### Path parameter [#path-parameter-13]

|  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](#param).

#### Request header [#request-header-13]

| 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 [#http-response-13]

#### Response body [#response-body-12]

If the returned HTTP status code is `200`, the request succeeds, and the response body contains the following fields:

| Parameter | Type | Description                                                                                                                                                                                                                                                                                                                  |
| :-------- | :--- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data`    | JSON | The delivery state of an offline message, in the format of `"message id": "delivery state"`. The delivery state: `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](./http-status-codes) for possible reasons.

### Example [#example-13]

#### Request example [#request-example-13]

```bash
# Replace {YourAppToken} with the app token generated in your server.
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer {YourAppToken}' 'http://XXXX/app-id/XXXX/users/user1/offline_msg_status/123'
```

#### Response example [#response-example-13]

```json
{
    "action": "get",
    "uri": "http://XXXX/app-id/XXXX/users/user1/offline_msg_status/123",
    "entities": [],
    "data": {
        "123": "delivered"
    },
    "timestamp": 1542601830084,
    "duration": 5,
    "count": 0
}
```

## Status codes [#status-codes]

For details, see [HTTP Status Codes](./http-status-codes).
