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.
Obtaining the User List (Deprecated)
1. API Description
API feature: obtain the user list in the specified cloud environment
API declaration: getEndUserList(options: Object): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| limit | Required | Number | Number of users to fetch |
| offset | Required | Number | offset |
3. Return Results
| Field | Type | Description |
|---|---|---|
| Total | Number | Total users |
| RequestId | String | Unique identifier of the request |
| Users | Array<EndUserInfo> | User information list |
EndUserInfo
| Field | Type | Description |
|---|---|---|
| UUId | String | Unique user identifier |
| WXOpenId | String | WeChat ID |
| QQOpenId | String | qq ID |
| Phone | String | Phone number |
| String | ||
| NickName | String | Nickname |
| Gender | String | Gender |
| AvatarUrl | String | Avatar URL |
| UpdateTime | String | Update time |
| CreateTime | String | Creation time |
| IsAnonymous | Boolean | Whether it is an anonymous user |
| IsDisabled | Boolean | whether the account is disabled |
| HasPassword | Boolean | Whether a password has been set |
| UserName | String | Username |
4. Sample Code
const cloudbaseConfig = {
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId" // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
};
const app = new CloudBase(cloudBaseConfig);
async function main() {
const { Users } = await app.user.getEndUserList({
limit: 20,
offset: 0
});
console.log(">>> Users are:", Users);
}
main();
Creating a New User (Deprecated)
1. API Description
API feature: Create username and password in the specified cloud environment
API declaration: createEndUser(options: Object): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| username | Yes | String | Username |
| password | Yes | String | Password |
Password length should be not less than 8 and not greater than 32, and should contain both letters and numbers.
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
| User | EndUserInfo | User information |
4. Sample Code
const cloudbaseConfig = {
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId" // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
};
const app = new CloudBase(cloudBaseConfig);
async function main() {
try {
const { User } = await app.user.createEndUser({
username: "your username",
password: "your password"
});
console.log(">>> New user information:", User);
} catch (error) {
console.log(">>> Create user failed:", error.message);
}
}
main();
Modifying User Account Information (Deprecated)
1. API Description
API feature: modify the information of a specific user in the specified cloud environment
API declaration: modifyEndUser(options: Object): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| uuid | required | String | TCB user unique identifier |
| username | No | String | New username |
| password | No | String | New password |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
4. Sample Code
const cloudbaseConfig = {
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId" // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
};
const app = new CloudBase(cloudBaseConfig);
async function main() {
try {
await app.user.modifyEndUser({
uuid: "your user uuid",
username: "your new username",
password: "your new password"
});
console.log(">>> User account information updated successfully");
} catch (error) {
console.log(">>> User account information update failed:", error.message);
}
}
main();
Modifying User Information (Deprecated)
1. API Description
API feature: modify the information of a specific user in the specified cloud environment
API declaration: updateEndUser(options: Object): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| uuid | required | String | TCB user unique identifier |
| nickName | required | String | New nickname |
| gender | required | String | New gender, `MALE |
| avatarUrl | required | String | New avatar |
| country | required | String | New country |
| province | required | String | New province |
| city | required | String | New city |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
4. Sample Code
const cloudbaseConfig = {
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId" // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
};
const app = new CloudBase(cloudBaseConfig);
async function main() {
try {
await app.user.updateEndUser({
uuid: "your user uuid",
nickName: "your new nickName",
gender: "your new gender",
avatarUrl: "your new avatarUrl",
country: "your new country",
province: "your new province",
city: "your new city"
});
console.log(">>> User information updated successfully");
} catch (error) {
console.log(">>> User information update failed:", error.message);
}
}
main();
Setting User Status (Deprecated)
1. API Description
API feature: disable or enable a specific user in the cloud environment
API declaration: setEndUserStatus(options: object): Promise<object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| uuid | required | String | TCB user unique identifier |
| status | Required | String | 'DISABLE' or 'ENABLE' |
3. Return Results
| Field | Type | Description |
|---|---|---|
| RequestId | String | Unique identifier of the request |
4. Sample Code
const cloudbaseConfig = {
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId" // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
};
const app = new CloudBase(cloudBaseConfig);
async function main() {
try {
const { RequestId } = await app.user.setEndUserStatus({
uuid: "User uuid",
status: "DISABLE"
});
console.log(">>> Disabled successfully");
} catch (error) {
console.log(">>> Disable failed", error.message);
}
}
main();
Batch Deleting Users (Deprecated)
1. API Description
API feature: Batch delete users in a specified cloud environment.
API declaration: deleteEndUsers(options: Object): Promise<Object>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| userList | Yes | Array<String> | User uuid list |
3. Return Results
| Field | Required | Type | Description |
|---|---|---|---|
| RequestId | Required | String | Unique identifier of the request |
4. Sample Code
const cloudbaseConfig = {
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId" // TCB environment ID, which can be obtained from the Tencent Cloud TCB console
};
const app = new CloudBase(cloudBaseConfig);
async function main() {
try {
const { RequestId } = await app.user.deleteEndUsers({
userList: [
"uuid a",
"uuid b",
"uuid c"
// ......
]
});
console.log(">>> Batch deletion successful");
} catch (error) {
console.log(">>> Batch deletion failed", error.message);
}
}
main();