Account Management

Listing users and groups in team/organisation

>>> from mbed_cloud import AccountManagementAPI
>>> accountApi = AccountManagementAPI()
>>>
>>> u = list(accountApi.list_users())[0]
>>> print("%r (%s)" % (u.full_name, u.email))
'David Bowie' (david.bowie@example.org)
>>>
>>> print(len(accountApi.list_groups().data))
13

Creating and managing a new user

>>> from mbed_cloud import AccountManagementAPI
>>> accountApi = AccountManagementAPI()
>>>
>>> # Create a new user with the bare minimum required information
>>> new_u = accountApi.add_user(username='fooo', email='foo@example.org')
>>> groups = list(accountApi.list_groups())

Reference

class mbed_cloud.account_management.AccountManagementAPI(params=None)

API reference for the AccountManagement API.

Exposing functionality for creating and managing accounts, users, groups and API keys in the organisation.

add_api_key(name, **kwargs)

Create new API key registered to organisation.

Parameters:
  • name (str) – The name of the API key (Required)
  • groups (list) – List of group IDs (str)
  • owner (str) – User ID owning the API key
  • status (str) – The status of the API key. Values: ACTIVE, INACTIVE
Returns:

Newly created API key object

Return type:

ApiKey

add_user(username, email, **kwargs)

Create a new user with provided details.

Add user example:

account_management_api = AccountManagementAPI()
# Add user
user = {
    "username": "test_user",
    "email": "test@gmail.com",
    "phone_number": "0123456789"
}
new_user = account_management_api.add_user(**user)
Parameters:
  • username (str) – The unique username of the user (Required)
  • email (str) – The unique email of the user (Required)
  • full_name (str) – The full name of the user
  • groups (list) – List of group IDs (str) which this user belongs to
  • password (str) – The password string of the user
  • phone_number (str) – Phone number of the user
  • terms_accepted (bool) – ‘General Terms & Conditions’ have been accepted
  • marketing_accepted (bool) – Marketing Information opt-in
Returns:

the new user object

Return type:

User

delete_api_key(api_key_id)

Delete an API key registered in the organisation.

Parameters:api_key_id (str) – The ID of the API key (Required)
Returns:void
delete_user(user_id)

Delete user specified user.

Parameters:user_id (str) – the ID of the user to delete (Required)
Returns:void
get_account()

Get details of the current account.

Returns:an account object.
Return type:Account
get_api_key(api_key_id)

Get API key details for key registered in organisation.

Parameters:api_key_id (str) – The ID of the API key to be updated (Required)
Returns:API key object
Return type:ApiKey
get_group(group_id)

Get details of the group.

Parameters:group_id (str) – The group ID (Required)
Returns:Group object.
Return type:Group
get_user(user_id)

Get user details of specified user.

Parameters:user_id (str) – the ID of the user to get (Required)
Returns:the user object with details about the user.
Return type:User
list_api_keys(**kwargs)

List the API keys registered in the organisation.

List api keys Example:

account_management_api = AccountManagementAPI()

# List api keys
api_keys_paginated_response = account_management_api.list_api_keys()
# get single api key
api_keys_paginated_response.data[0]
Parameters:
  • limit (int) – Number of API keys to get
  • after (str) – Entity ID after which to start fetching
  • order (str) – Order of the records to return (asc|desc)
  • filters (dict) – Dictionary of filters to apply: str owner (eq)
Returns:

a list of ApiKey objects

Return type:

PaginatedResponse

Raises:

ApiException

list_group_api_keys(group_id, **kwargs)

List API keys of a group.

Parameters:
  • group_id (str) – The group ID (Required)
  • limit (int) – The number of api keys to retrieve.
  • order (str) – The ordering direction, ascending (asc) or descending (desc).
  • after (str) – Get API keys after/starting at given api key ID.
Returns:

a list of ApiKey objects.

Return type:

PaginatedResponse

list_group_users(group_id, **kwargs)

List users of a group.

Parameters:
  • group_id (str) – The group ID (Required)
  • limit (int) – The number of users to retrieve
  • order (str) – The ordering direction, ascending (asc) or descending (desc)
  • after (str) – Get API keys after/starting at given user ID
Returns:

a list of User objects.

Return type:

PaginatedResponse

list_groups(**kwargs)

List all groups in organisation.

Parameters:
  • limit (int) – The number of groups to retrieve
  • order (str) – The ordering direction, ascending (asc) or descending (desc)
  • after (str) – Get groups after/starting at given group ID
Returns:

a list of Group objects.

Return type:

PaginatedResponse

list_users(**kwargs)

List all users in organisation.

Parameters:
  • limit (int) – The number of users to retrieve
  • order (str) – The ordering direction, ascending (asc) or descending (desc)
  • after (str) – Get users after/starting at given user ID
  • filters (dict) – Dictionary of filters to apply: str status (eq)
Returns:

a list of User objects

Return type:

PaginatedResponse

update_account(**kwargs)

Update details of account associated with current API key.

Parameters:
  • address_line1 (str) – Postal address line 1.
  • address_line2 (str) – Postal address line 2.
  • city (str) – The city part of the postal address.
  • display_name (str) – The display name for the account.
  • country (str) – The country part of the postal address.
  • company (str) – The name of the company.
  • state (str) – The state part of the postal address.
  • contact (str) – The name of the contact person for this account.
  • postal_code (str) – The postal code part of the postal address.
  • parent_id (str) – The ID of the parent account.
  • phone_number (str) – The phone number of the company.
  • email (str) – Email address for this account.
  • aliases (list[str]) – List of aliases
Returns:

an account object.

Return type:

Account

update_api_key(api_key_id, **kwargs)

Update API key.

Parameters:
  • api_key_id (str) – The ID of the API key to be updated (Required)
  • name (str) – The name of the API key
  • owner (str) – User ID owning the API key
  • status (str) – The status of the API key. Values: ACTIVE, INACTIVE
Returns:

Newly created API key object

Return type:

ApiKey

update_user(user_id, **kwargs)

Update user properties of specified user.

Parameters:
  • user_id (str) – The ID of the user to update (Required)
  • username (str) – The unique username of the user
  • email (str) – The unique email of the user
  • full_name (str) – The full name of the user
  • password (str) – The password string of the user.
  • phone_number (str) – Phone number of the user
  • terms_accepted (bool) – Is ‘General Terms & Conditions’ accepted
  • marketing_accepted (bool) – Is receiving marketing information accepted?
Returns:

the updated user object

Return type:

User

class mbed_cloud.account_management.Account(dictionary)

Describes account object.

Example usage:

api = AccountManagementAPI()

# Get account owning the API key in use
current_account = api.get_account()
print(current_account.company)
address_line1

Postal address line 1.

Return type:str
address_line2

Postal address line 2.

Return type:str
aliases

An array of aliases.

Return type:str[]
city

The city part of the postal address.

Return type:str
company

The name of the company.

Return type:str
contact

The name of the contact person for this account.

Return type:str
contract_number

Gets the contract_number of this AccountInfo.

Contract number of the customer.

Returns:The contract_number of this AccountInfo.
Return type:str
country

The country part of the postal address.

Return type:str
created_at

Creation UTC time RFC3339.

Return type:datetime
customer_number

Gets the customer_number of this AccountInfo.

Customer number of the customer.

Returns:The customer_number of this AccountInfo.
Return type:str
display_name

The display name for the account.

Return type:str
email

The company email address for this account.

Return type:str
expiry_warning

Gets the expiry_warning of this AccountInfo.

Indicates how many days (1-180) before account expiration a notification email should be sent.

Returns:The expiration_warning_threshold of this AccountInfo.
Return type:str
id

Account ID (readonly).

Return type:str
limits

List of limits as key-value pairs if requested.

Return type:list of Limits
multifactor_authentication_status

Gets the multifactor_authentication_status of this AccountInfo.

The enforcement status of the multi-factor authentication, either ‘enforced’ or ‘optional’.

Returns:The mfa_status of this AccountInfo.
Return type:str
notification_emails

Gets the notification_emails of this AccountInfo.

A list of notification email addresses.

Returns:The notification_emails of this AccountInfo.
Return type:list[str]
phone_number

The phone number of the company.

Return type:str
policies

List of policies if requested.

Return type:list of Policies
postcode

The postal code part of the postal address.

Return type:str
provisioning_allowed

Flag (true/false) indicating whether Factory Tool is allowed to download or not.

Return type:bool
reason

A note about the reason for updating the status of the account.

Return type:str
reference_note

Gets the reference_note of this AccountInfo.

A reference note for updating the status of the account

Returns:The reference_note of this AccountInfo.
Return type:str
sales_contact_email

Gets the sales_contact_email of this AccountInfo.

Email address of the sales contact.

Returns:The sales_contact_email of this AccountInfo.
Return type:str
state

The state part of the postal address.

Return type:str
status

The status of the account.

values: ENROLLING, ACTIVE, RESTRICTED, SUSPENDED

Return type:str
template_id

Account template ID.

Return type:str
tier

The tier level of the account; ‘0’: free tier, ‘1’: commercial account.

Other values are reserved for the future.

Return type:str
update_attributes(updates)

Update attributes.

updated_at

Gets the updated_at of this AccountInfo.

Last update UTC time RFC3339.

Returns:The updated_at of this AccountInfo.
Return type:datetime
upgraded_at

Time when upgraded to commercial account in UTC format RFC3339.

Return type:datetime
class mbed_cloud.account_management.User(dictionary)

Describes user object.

Example usage:

api = AccountManagementAPI()

# Listing existing users
for idx, user in enumerate(api.list_users())
    print(user.full_name)

# Creating a new user
new_user = api.add_user("username",
                        "user@example.org",
                        full_name = "David Bowie",
                        password = "hunter2")
account_id

The UUID of the account (readonly).

Return type:str
address

Address.

Return type:str
created_at

Creation UTC time RFC3339 (readonly).

Return type:datetime
creation_time

A timestamp of the user creation in the storage, in milliseconds (readonly).

Return type:int
email

The email address.

Return type:str
email_verified

A flag indicating whether the user’s email address has been verified or not.

Return type:bool
full_name

The full name of the user.

Return type:str
groups

A list of group IDs this user belongs to (readonly).

Return type:str[]
id

The UUID of the user (readonly).

Return type:str
last_login_time

A timestamp of the latest login of the user, in milliseconds (readonly).

Return type:int
login_history

History of logins for this user (readonly).

Returns:List of LoginHistory.
Return type:LoginHistory
marketing_accepted

A flag indicating that receiving marketing information has been accepted.

Return type:bool
password

The password when creating a new user. It will be generated when not present in the request.

Return type:str
password_changed_time

A timestamp of the latest change of the user password, in milliseconds (readonly).

Return type:int
phone_number

Phone number.

Return type:str
status

The status of the user (readonly).

INVITED means that the user has not accepted the invitation request. RESET means that the password must be changed immediately. values: ENROLLING, INVITED, ACTIVE, RESET, INACTIVE

Return type:str
terms_accepted

A flag indicating that the General Terms and Conditions has been accepted.

Return type:bool
two_factor_authentication

Whether two factor authentication has been enabled for this user (readonly).

Return type:bool
update_attributes(updates)

Update attributes.

username

A username containing alphanumerical letters and -,._@+= characters.

Return type:str
class mbed_cloud.account_management.Group(dictionary)

Describes group object.

Example usage:

api = AccountManagementAPI()

# Listing existing groups
for idx, g in enumerate(api.list_groups())
    print(g.name)
account_id

The UUID of the account this group belongs to. (readonly)

Return type:str
api_key_count

The number of API keys in this group. (readonly)

Return type:int
created_at

Creation UTC time RFC3339. (readonly)

Return type:datetime
creation_time

A timestamp of the group creation in the storage, in milliseconds. (readonly)

Return type:int
id

The UUID of the group. (readonly)

Return type:str
last_update_time

The last update time

Return type:datetime
name

The name of the group. (readonly)

Return type:str
update_attributes(updates)

Update attributes.

user_count

The number of users in this group. (readonly)

Return type:int
class mbed_cloud.account_management.ApiKey(dictionary)

Describes API key object.

Example usage:

api = AccountManagementAPI()

# Listing existing keys
for idx, k in enumerate(api.list_api_keys()):
    print(k.name, k.key)

# Creating a new key
new_k = api.add_api_key("New key name")
print(new_k.key)
created_at

Creation UTC time RFC3339. (readonly)

Return type:datetime
creation_time

The timestamp of the API key creation in the storage, in milliseconds. (readonly)

Return type:int
groups

A list of group IDs this API key belongs to.

Return type:str[]
id

The UUID of the API key. (readonly)

Return type:str
key

The API key. (readonly)

Return type:str
last_login_time

The timestamp of the latest API key usage, in milliseconds. (readonly)

Return type:int
name

The display name for the API key.

Return type:str
owner_id

The owner of this API key, who is the creator by default.

Return type:str
status

The status of the API key. (readonly)

values: ACTIVE, INACTIVE

Return type:str
update_attributes(updates)

Update attributes.

class mbed_cloud.account_management.LoginHistory(dictionary)

Login History.

date

Date of login.

Return type:datetime
ip_address

IP Address login from.

Return type:str
success

Whether login was successful.

Return type:bool
update_attributes(updates)

Update attributes.

user_agent

User agent used for login.

Return type:str