b2c_tooling_sdk.operations.users
Account Manager user management operations.
Mirrors src/operations/users/index.ts. Provides high-level functions for managing users in Account Manager, including CRUD operations, role management, and user lifecycle operations.
Core User Functions
get_user-- Get user details by IDget_user_by_login-- Get user details by login (email)list_users-- List users with paginationcreate_user-- Create a new userupdate_user-- Update an existing userdelete_user-- Disable a user (soft delete)purge_user-- Purge a disabled user (hard delete)reset_user-- Reset a user to INITIAL state
Usage
from b2c_tooling_sdk.operations.users import get_user_by_login, list_users, create_user, CreateUserOptions
from b2c_tooling_sdk.clients import create_account_manager_users_client
from b2c_tooling_sdk.auth import OAuthStrategy
auth = OAuthStrategy(client_id="your-client-id", client_secret="your-client-secret")
client = create_account_manager_users_client(config, auth)
# Get a user by login
user = await get_user_by_login(client, "user@example.com")
# List users
users = await list_users(client, ListUsersOptions(size=25, page=0))
# Create a new user
new_user = await create_user(
client,
CreateUserOptions(
user={
"mail": "newuser@example.com",
"firstName": "John",
"lastName": "Doe",
"organizations": ["org-id"],
"primaryOrganization": "org-id",
}
),
)Authentication
User operations require OAuth authentication with appropriate Account Manager permissions.
Classes
CreateUserOptions
class CreateUserOptionsOptions for creating a user.
Fields
| Name | Type |
|---|---|
user | UserCreate |
GrantRoleOptions
class GrantRoleOptionsOptions for granting a role.
The AM API uses mixed formats: role IDs (e.g. bm-admin) in the roles array, and roleEnumNames (e.g. ECOM_ADMIN) in the roleTenantFilter string. Both must be provided. Use resolve_to_internal_role / resolve_from_internal_role to convert.
Fields
| Name | Type | Default |
|---|---|---|
user_id | str | |
role | str | |
role_enum_name | str | |
scope | str | None | None |
RevokeRoleOptions
class RevokeRoleOptionsOptions for revoking a role.
See GrantRoleOptions for details on the mixed role ID formats.
Fields
| Name | Type | Default |
|---|---|---|
user_id | str | |
role | str | |
role_enum_name | str | |
scope | str | None | None |
UpdateUserOptions
class UpdateUserOptionsOptions for updating a user.
Fields
| Name | Type |
|---|---|
user_id | str |
changes | UserUpdate |
Functions
create_user
async def create_user(client: AccountManagerUsersClient, options: CreateUserOptions) -> AccountManagerUserCreate a new user.
Parameters
| Name | Type | Description |
|---|---|---|
client | AccountManagerUsersClient | Account Manager client. |
options | CreateUserOptions | Create options (user details). |
Returns: Created user.
get_user_by_login
async def get_user_by_login(client: AccountManagerUsersClient, login: str) -> AccountManagerUserRetrieve details of a user by login (email).
This searches through paginated results to find the user.
Parameters
| Name | Type | Description |
|---|---|---|
client | AccountManagerUsersClient | Account Manager client. |
login | str | User login (email). |
Returns: User details.
Raises
RuntimeError— If the user is not found.
grant_role
async def grant_role(client: AccountManagerUsersClient, options: GrantRoleOptions) -> AccountManagerUserGrant a role to a user, optionally with scope.
This updates the user's roles and roleTenantFilter.
Parameters
| Name | Type | Description |
|---|---|---|
client | AccountManagerUsersClient | Account Manager client. |
options | GrantRoleOptions | Grant options (userId, role, optional scope). |
Returns: Updated user.
revoke_role
async def revoke_role(client: AccountManagerUsersClient, options: RevokeRoleOptions) -> AccountManagerUserRevoke a role from a user, optionally removing specific scope.
Parameters
| Name | Type | Description |
|---|---|---|
client | AccountManagerUsersClient | Account Manager client. |
options | RevokeRoleOptions | Revoke options (userId, role, optional scope). |
Returns: Updated user.
update_user
async def update_user(client: AccountManagerUsersClient, options: UpdateUserOptions) -> AccountManagerUserUpdate an existing user.
Parameters
| Name | Type | Description |
|---|---|---|
client | AccountManagerUsersClient | Account Manager client. |
options | UpdateUserOptions | Update options (userId, changes). |
Returns: Updated user.
Re-exports
Also exported from this module; documented elsewhere: