Skip to main content

User Management

createUser

1. API Description

API feature: Create user with username and password login

API declaration: app.user.createUser(options): Promise<Object>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
nameRequiredStringUsername, 1~64 characters, must start with a letter/digit, and only letters, digits, ., _, - are allowed
uidNoStringCustom user UID, up to 64 characters long
typeNoStringUser type: internalUser (internal) or externalUser (external)
passwordNoStringPassword, 8~32 characters, must include at least 3 types of the following: uppercase letters, lowercase letters, digits, and special characters
userStatusNoStringInitial status: ACTIVE (active) or BLOCKED (blocked), default ACTIVE
nickNameNoStringNickname, 2~64 characters long
phoneNoStringPhone number (11-digit Chinese mainland number)
emailNoStringEmail
avatarUrlNoStringAvatar URL
descriptionNoStringDescription, up to 200 characters

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request
Data.UidStringCreated 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>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
pageNoNoNumberPage number, starting from 1, default 1
pageSizeNoNumberNumber of items per page, 1 to 100, default 20
nameNoStringFilter by username
nickNameNoStringFilter by nickname
phoneNoStringFilter by phone number
emailNoStringFilter by email

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request
Data.TotalNumberTotal users
Data.UserListArrayUser list, see below TcbUserItem

TcbUserItem

FieldTypeDescription
UidStringUser UID
NameStringUsername
TypeStringUser type
UserStatusStringUser status: ACTIVE or BLOCKED
NickNameStringNickname
PhoneStringPhone number
EmailStringEmail
AvatarUrlStringAvatar URL
DescriptionStringDescription

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>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
uidRequiredStringUser UID
nameNoStringNew username (pass an empty string to leave unchanged)
typeNoStringNew user type: internalUser or externalUser
passwordNoStringNew password (pass an empty string to leave unchanged)
userStatusNoStringNew status: ACTIVE or BLOCKED
nickNameNoStringNew nickname (pass an empty string to clear)
phoneNoStringNew phone number (pass an empty string to clear)
emailNoStringNew email (pass an empty string to clear)
avatarUrlNoStringNew avatar URL (pass an empty string to clear)
descriptionNoStringNew description (pass an empty string to clear)
Field Update Rules
  • name, password: Only updated when a non-empty string is passed; ignored if an empty string is passed or not passed
  • nickName, 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

FieldTypeDescription
RequestIdStringUnique identifier of the request
Data.SuccessBooleanwhether 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>

version tip

This API has been supported since v5.0.0.

2. Input Parameters

FieldRequiredTypeDescription
uidsRequiredString[]List of user UIDs to be deleted, up to 100

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request
Data.SuccessCountNumberSuccessful deletion count
Data.FailedCountNumberFailed 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`)
}

Deprecated

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

FieldRequiredTypeDescription
limitRequiredNumberNumber of users to fetch
offsetRequiredNumberoffset

3. Return Results

FieldTypeDescription
TotalNumberTotal users
RequestIdStringUnique identifier of the request
UsersArray<EndUserInfo>User information list

EndUserInfo

FieldTypeDescription
UUIdStringUnique user identifier
WXOpenIdStringWeChat ID
QQOpenIdStringqq ID
PhoneStringPhone number
EmailStringEmail
NickNameStringNickname
GenderStringGender
AvatarUrlStringAvatar URL
UpdateTimeStringUpdate time
CreateTimeStringCreation time
IsAnonymousBooleanWhether it is an anonymous user
IsDisabledBooleanwhether the account is disabled
HasPasswordBooleanWhether a password has been set
UserNameStringUsername

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

FieldRequiredTypeDescription
usernameYesStringUsername
passwordYesStringPassword
Password Strength Requirements

Password length should be not less than 8 and not greater than 32, and should contain both letters and numbers.

3. Return Results

FieldTypeDescription
RequestIdStringUnique identifier of the request
UserEndUserInfoUser 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

FieldRequiredTypeDescription
uuidrequiredStringTCB user unique identifier
usernameNoStringNew username
passwordNoStringNew password

3. Return Results

FieldTypeDescription
RequestIdStringUnique 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

FieldRequiredTypeDescription
uuidrequiredStringTCB user unique identifier
nickNamerequiredStringNew nickname
genderrequiredStringNew gender, `MALE
avatarUrlrequiredStringNew avatar
countryrequiredStringNew country
provincerequiredStringNew province
cityrequiredStringNew city

3. Return Results

FieldTypeDescription
RequestIdStringUnique 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

FieldRequiredTypeDescription
uuidrequiredStringTCB user unique identifier
statusRequiredString'DISABLE' or 'ENABLE'

3. Return Results

FieldTypeDescription
RequestIdStringUnique 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

FieldRequiredTypeDescription
userListYesArray<String>User uuid list

3. Return Results

FieldRequiredTypeDescription
RequestIdRequiredStringUnique 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();