User Management
createUser
1. API Description
API feature: Create user with username and password login
API declaration: app.user.createUser(options): Promise<Object>
This API has been supported since v5.0.0.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| name | Required | String | Username, 1~64 characters, must start with a letter/digit, and only letters, digits, ., _, - are allowed |
| uid | No | String | Custom user UID, up to 64 characters long |
| type | No | String | User type: internalUser (internal) or externalUser (external) |
| password | No | String | Password, 8~32 characters, must include at least 3 types of the following: uppercase letters, lowercase letters, digits, and special characters |
| userStatus | No | String | Initial status: ACTIVE (active) or BLOCKED (blocked), default ACTIVE |
| nickName | No | String | Nickname, 2~64 characters long |
| phone | No | String | Phone number (11-digit Chinese mainland number) |
| No | String | ||
| avatarUrl | No | String | Avatar URL |
| description | No | String | Description, up to 200 characters |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
| Data.Uid | String | Created user UID |
4. Sample Code
const app = CloudBase.init({ secretId, secretKey, envId })
async function main() {
const res = await app.user.createUser({
name: 'alice',
password: 'Abc@12345',
type: 'internalUser',
nickName: 'Alice',
email: 'alice@example.com'
})
console.log('New user UID:', res.Data.Uid)
}
describeUserList
1. API Description
API feature: paginated query of user list, supports filtering by username, nickname, phone number, and email
API declaration: app.user.describeUserList(options?): Promise<Object>
This API has been supported since v5.0.0.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| pageNo | No | Number | Page number, starting from 1, default 1 |
| pageSize | No | Number | Number of items per page, 1 to 100, default 20 |
| name | No | String | Filter by username |
| nickName | No | String | Filter by nickname |
| phone | No | String | Filter by phone number |
| No | String | Filter by email |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
| Data.Total | Number | Total users |
| Data.UserList | Array | User list, see below TcbUserItem |
TcbUserItem
| Field | Type | Description |
|---|---|---|
| Uid | String | User UID |
| Name | String | Username |
| Type | String | User type |
| UserStatus | String | User status: ACTIVE or BLOCKED |
| NickName | String | Nickname |
| Phone | String | Phone number |
| String | ||
| AvatarUrl | String | Avatar URL |
| Description | String | Description |
4. Sample Code
async function main() {
const res = await app.user.describeUserList({ pageNo: 1, pageSize: 20 })
console.log(`Total ${res.Data.Total} users`)
res.Data.UserList.forEach(u => console.log(u.Uid, u.Name, u.UserStatus))
}
modifyUser
1. API Description
API feature: Modify user information, including password, user status, etc.
API declaration: app.user.modifyUser(options): Promise<Object>
This API has been supported since v5.0.0.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| uid | Required | String | User UID |
| name | No | String | New username (pass an empty string to leave unchanged) |
| type | No | String | New user type: internalUser or externalUser |
| password | No | String | New password (pass an empty string to leave unchanged) |
| userStatus | No | String | New status: ACTIVE or BLOCKED |
| nickName | No | String | New nickname (pass an empty string to clear) |
| phone | No | String | New phone number (pass an empty string to clear) |
| No | String | New email (pass an empty string to clear) | |
| avatarUrl | No | String | New avatar URL (pass an empty string to clear) |
| description | No | String | New description (pass an empty string to clear) |
name,password: Only updated when a non-empty string is passed; ignored if an empty string is passed or not passednickName,phone,email,avatarUrl,description: Passed to the backend as long as the field is included (even if empty); passing an empty string clears the field
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
| Data.Success | Boolean | whether the modification was successful |
4. Sample Code
async function main() {
// Ban a user
await app.user.modifyUser({
uid: 'user-uid-xxx',
userStatus: 'BLOCKED'
})
// Change password
await app.user.modifyUser({
uid: 'user-uid-xxx',
password: 'NewPass@2025'
})
}
deleteUsers
1. API Description
API feature: Batch delete users (irreversible)
API declaration: app.user.deleteUsers(options): Promise<Object>
This API has been supported since v5.0.0.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| uids | Required | String[] | List of user UIDs to be deleted, up to 100 |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
| Data.SuccessCount | Number | Successful deletion count |
| Data.FailedCount | Number | Failed deletion count |
4. Sample Code
async function main() {
const res = await app.user.deleteUsers({
uids: ['uid-a', 'uid-b', 'uid-c']
})
console.log(`Successfully deleted ${res.Data.SuccessCount} users`)
}
The following APIs have been deprecated. It is recommended to migrate to the new version of the APIs above.