Skip to main content

Admin Customer — TypeScript SDK

End-customer (bizUser) lifecycle: list, create, delete.

Overview​

The admin Customer resource manages end-customers (the bizUser layer — the actual paying users under the admin's tenant), distinct from admin operators themselves. For partner_admin, the scope is the admin's own tenant; for sys_admin, scope is broader per backend policy.

Accessed via admin.customer.

Available Operations​

MethodDescription
list()List end-customers under the admin's scope
create()Create a new end-customer
delete()Delete an end-customer by id

list​

List end-customers under the current admin's scope, paginated. Supports fuzzy search by userName.

Example Usage​

const result = await admin.customer.list({ pageNum: 1, pageSize: 20 });
console.log(`total: ${result.total}`);
for (const it of result.list) {
console.log(it.id, it.userName, it.email);
}

Search by name:

const result = await admin.customer.list({ userName: 'acme', pageNum: 1, pageSize: 10 });

Parameters​

ParameterTypeRequiredDefaultDescription
pageNumnumberNo1Page number, starting from 1
pageSizenumberNo10Items per page
userNamestringNo--Fuzzy search by userName

Response​

Returns an object with total, list, totalPages, currentPage, pageSize. Each item exposes id, userName, email, phone, timezone, createdAtUtc, updatedAtUtc, userType, parentId, etc.

Errors​

CodeExceptionWhen
2007PermissionErrorAdmin lacks Customer Management permission
3001AuthenticationErrorSession expired and refresh failed

create​

Create a new end-customer under the current admin's tenant. Returns true on success; the created id is not echoed — recover it via list() with the matching userName if needed.

Example Usage​

const ok = await admin.customer.create({
userName: 'acme-user-1',
password: 'StrongPass!',
email: 'user1@acme.example',
});
console.log(ok); // true

Recover the created id:

const result = await admin.customer.list({ userName: 'acme-user-1', pageNum: 1, pageSize: 1 });
const newId = result.list[0].id;

Parameters​

ParameterTypeRequiredDefaultDescription
userNamestringYes--New customer userName (must be unique in scope)
passwordstringYes--Initial password (server-side bcrypt-hashed)
emailstringNo--Contact email
phonestringNo--Contact phone
timezonestringNoAsia/ShanghaiIANA timezone

Response​

Returns boolean — true on success. On failure throws the appropriate exception.

Errors​

CodeExceptionWhen
1001ValidationErrorMissing required field, weak password, or bad email format
2007PermissionErrorAdmin lacks Customer Management permission
3001AuthenticationErrorSession expired and refresh failed
Server 4xxWltErrorDuplicate userName in the tenant scope

delete​

Delete an end-customer by id.

Example Usage​

const ok = await admin.customer.delete(42);
console.log(ok); // true

// Verify no residue
const remaining = await admin.customer.list({ userName: 'acme-user-1', pageNum: 1, pageSize: 10 });
console.assert(remaining.list.length === 0);

Parameters​

ParameterTypeRequiredDefaultDescription
userIdnumberYes--End-customer id to delete (positional argument)

Response​

Returns boolean — true on success.

Errors​

CodeExceptionWhen
1001ValidationErrorInvalid userId
2007PermissionErrorAdmin lacks Customer Management permission
3001AuthenticationErrorSession expired and refresh failed
Server 4xxWltErrorCustomer does not exist or is out of scope

Typical lifecycle​

The full create → verify → delete → verify pattern (useful for provisioning scripts and integration tests):

const temp = 'provisioning-test';
const ok = await admin.customer.create({ userName: temp, password: 'StrongPass!', email: 't@example.com' });
const found = await admin.customer.list({ userName: temp, pageNum: 1, pageSize: 1 });
const newId = found.list[0].id;

// ... do work under `newId` ...

await admin.customer.delete(newId);
const after = await admin.customer.list({ userName: temp, pageNum: 1, pageSize: 10 });
console.assert(after.list.length === 0);