---
editLink: false
lastUpdated: false
outline: [2, 3]
---

<!-- Generated by python/b2c-tooling-sdk/scripts/generate_api_docs.py. Do not edit. -->

# 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`](/python/api/clients#get-user) -- Get user details by ID
- [`get_user_by_login`](/python/api/operations/users#get-user-by-login) -- Get user details by login (email)
- [`list_users`](/python/api/clients#list-users) -- List users with pagination
- [`create_user`](/python/api/operations/users#create-user) -- Create a new user
- [`update_user`](/python/api/operations/users#update-user) -- Update an existing user
- [`delete_user`](/python/api/clients#delete-user) -- Disable a user (soft delete)
- [`purge_user`](/python/api/clients#purge-user) -- Purge a disabled user (hard delete)
- [`reset_user`](/python/api/clients#reset-user) -- Reset a user to INITIAL state

## Usage

```python
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 {#createuseroptions}

```python
class CreateUserOptions
```

Options for creating a user.

**Fields**

| Name | Type |
| --- | --- |
| `user` | `UserCreate` |

### GrantRoleOptions {#grantroleoptions}

```python
class GrantRoleOptions
```

Options 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 {#revokeroleoptions}

```python
class RevokeRoleOptions
```

Options for revoking a role.

See [`GrantRoleOptions`](/python/api/operations/users#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 {#updateuseroptions}

```python
class UpdateUserOptions
```

Options for updating a user.

**Fields**

| Name | Type |
| --- | --- |
| `user_id` | `str` |
| `changes` | `UserUpdate` |

## Functions

### create_user {#create-user}

```python
async def create_user(client: AccountManagerUsersClient, options: CreateUserOptions) -> AccountManagerUser
```

Create 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 {#get-user-by-login}

```python
async def get_user_by_login(client: AccountManagerUsersClient, login: str) -> AccountManagerUser
```

Retrieve 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 {#grant-role}

```python
async def grant_role(client: AccountManagerUsersClient, options: GrantRoleOptions) -> AccountManagerUser
```

Grant 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 {#revoke-role}

```python
async def revoke_role(client: AccountManagerUsersClient, options: RevokeRoleOptions) -> AccountManagerUser
```

Revoke 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 {#update-user}

```python
async def update_user(client: AccountManagerUsersClient, options: UpdateUserOptions) -> AccountManagerUser
```

Update 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:

- [`AccountManagerUser`](/python/api/clients#accountmanageruser)
- [`UserCollection`](/python/api/clients#usercollection)
- [`UserCreate`](/python/api/clients#usercreate)
- [`UserUpdate`](/python/api/clients#userupdate)
- [`delete_user`](/python/api/clients#delete-user)
- [`get_user`](/python/api/clients#get-user)
- [`list_users`](/python/api/clients#list-users)
- [`purge_user`](/python/api/clients#purge-user)
- [`reset_user`](/python/api/clients#reset-user)
