Admin Customer — Python 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
| Method | Description |
|---|---|
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 user_name.
Example Usage
result = admin.customer.list(page_num=1, page_size=20)
print(f"total: {result['total']}")
for it in result["list"]:
print(it["id"], it["userName"], it["email"])
Search by name:
result = admin.customer.list(user_name="acme", page_num=1, page_size=10)
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| page_num | int | No | 1 | Page number, starting from 1 |
| page_size | int | No | 10 | Items per page |
| user_name | str | No | -- | Fuzzy search by userName |
Response
Returns a dict with total, list, totalPages, currentPage, pageSize. Each item exposes id, userName, email, phone, timezone, createdAtUtc, updatedAtUtc, userType, parentId, etc.
Errors
| Code | Exception | When |
|---|---|---|
2007 | PermissionError | Admin lacks Customer Management permission |
3001 | AuthenticationError | Session 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 user_name if needed.
Example Usage
ok = admin.customer.create(
user_name="acme-user-1",
password="StrongPass!",
email="user1@acme.example",
)
print(ok) # True
Recover the created id:
result = admin.customer.list(user_name="acme-user-1", page_num=1, page_size=1)
new_id = result["list"][0]["id"]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| user_name | str | Yes | -- | New customer userName (must be unique in scope) |
| password | str | Yes | -- | Initial password (server-side bcrypt-hashed) |
| str | No | -- | Contact email | |
| phone | str | No | -- | Contact phone |
| timezone | str | No | Asia/Shanghai | IANA timezone |
Response
Returns bool — True on success. On failure raises the appropriate exception.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Missing required field, weak password, or bad email format |
2007 | PermissionError | Admin lacks Customer Management permission |
3001 | AuthenticationError | Session expired and refresh failed |
| Server 4xx | WltError | Duplicate user_name in the tenant scope |
delete
Delete an end-customer by id.
Example Usage
ok = admin.customer.delete(user_id=42)
print(ok) # True
# Verify no residue
remaining = admin.customer.list(user_name="acme-user-1", page_num=1, page_size=10)
assert len(remaining["list"]) == 0
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| user_id | int | Yes | -- | End-customer id to delete |
Response
Returns bool — True on success.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Invalid user_id |
2007 | PermissionError | Admin lacks Customer Management permission |
3001 | AuthenticationError | Session expired and refresh failed |
| Server 4xx | WltError | Customer does not exist or is out of scope |
Typical lifecycle
The full create → verify → delete → verify pattern (useful for provisioning scripts and integration tests):
temp = "provisioning-test"
ok = admin.customer.create(user_name=temp, password="StrongPass!", email="t@example.com")
found = admin.customer.list(user_name=temp, page_num=1, page_size=1)
new_id = found["list"][0]["id"]
# ... do work under `new_id` ...
admin.customer.delete(user_id=new_id)
after = admin.customer.list(user_name=temp, page_num=1, page_size=10)
assert len(after["list"]) == 0