Directory

class O365.directory.Directory(*, parent=None, con=None, **kwargs)[source]

Bases: ApiComponent

__init__(*, parent=None, con=None, **kwargs)[source]

Represents the Active Directory

Parameters:
  • parent (Account) – parent object

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

get_current_user(query=None)[source]

Returns the current logged-in user

get_user(user, query=None)[source]

Returns a User by it’s id or user principal name

Parameters:

user (str) – the user id or user principal name

Returns:

User for specified email

Return type:

User

get_user_direct_reports(user, limit=100, *, query=None, order_by=None, batch=None)[source]

Gets a list of direct reports for the user provided from the active directory

When querying the Active Directory the Users endpoint will be used.

Also using endpoints has some limitations on the querying capabilities.

To use query an order_by check the OData specification here: http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/ part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions -complete.html

Parameters:
  • limit (int or None) – max no. of contacts to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns:

list of users

Return type:

list[User] or Pagination

get_user_manager(user, query=None)[source]

Returns a Users’ manager by the users id, or user principal name

Parameters:

user (str) – the user id or user principal name

Returns:

User for specified email

Return type:

User

get_users(limit=100, *, query=None, order_by=None, batch=None)[source]

Gets a list of users from the active directory

When querying the Active Directory the Users endpoint will be used. Only a limited set of information will be available unless you have access to scope ‘User.Read.All’ which requires App Administration Consent.

Also using endpoints has some limitations on the querying capabilities.

To use query an order_by check the OData specification here: http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/ part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions -complete.html

Parameters:
  • limit (int or None) – max no. of contacts to get. Over 999 uses batch.

  • query (Query or str) – applies a OData filter to the request

  • order_by (Query or str) – orders the result set based on this condition

  • batch (int) – batch size, retrieves items in batches allowing to retrieve more items than the limit.

Returns:

list of users

Return type:

list[User] or Pagination

class O365.directory.User(*, parent=None, con=None, **kwargs)[source]

Bases: ApiComponent

__init__(*, parent=None, con=None, **kwargs)[source]

Represents an Azure AD user account

Parameters:
  • parent (Account) – parent object

  • con (Connection) – connection to use if no parent specified

  • protocol (Protocol) – protocol to use if no parent specified (kwargs)

  • main_resource (str) – use this resource instead of parent resource (kwargs)

get_profile_photo(size=None)[source]

Returns the user profile photo

Parameters:

size (str) – 48x48, 64x64, 96x96, 120x120, 240x240, 360x360, 432x432, 504x504, and 648x648

new_message(recipient=None, *, recipient_type=RecipientType.TO)[source]

This method returns a new draft Message instance with this user email as a recipient

Parameters:
  • recipient (Recipient) – a Recipient instance where to send this message. If None the email of this contact will be used

  • recipient_type (RecipientType) – section to add recipient into

Returns:

newly created message

Return type:

Message or None

update_profile_photo(photo)[source]

Updates this user profile photo :param bytes photo: the photo data in bytes

about_me

A freeform text entry field for the user to describe themselves.

   Type: str

account_enabled

true if the account is enabled; otherwise, false.

   Type: str

age_group

The age group of the user.

   Type: ageGroup

assigned_licenses

The licenses that are assigned to the user, including inherited (group-based) licenses.

   Type: list[assignedLicenses]

assigned_plans

The plans that are assigned to the user.

   Type: list[assignedPlans]

birthday

The birthday of the user.

   Type: datetime

business_phones

The telephone numbers for the user.

   Type: list[str]

city

The city where the user is located.

   Type: str

company_name

The name of the company that the user is associated with.

   Type: str

consent_provided_for_minor

Whether consent was obtained for minors.

   Type: consentProvidedForMinor

country

The country or region where the user is located; for example, US or UK.

   Type: str

created

The date and time the user was created.

   Type: datetime

department

The name of the department in which the user works.

   Type: str

display_name

The name displayed in the address book for the user.

   Type: str

employee_id

The employee identifier assigned to the user by the organization.

   Type: str

fax_number

The fax number of the user.

   Type: str

property full_name

Full Name (Name + Surname) :rtype: str

given_name

The given name (first name) of the user.

   Type: str

hire_date

The type of the user.

   Type: str

im_addresses

The instant message voice-over IP (VOIP) session initiation protocol (SIP) addresses for the user.

   Type: str

interests

A list for the user to describe their interests.

   Type: list[str]

is_resource_account

Don’t use – reserved for future use.

   Type: bool

job_title

The user’s job title.

   Type: str

last_password_change

The time when this Microsoft Entra user last changed their password or when their password was created, whichever date the latest action was performed.

   Type: str

legal_age_group_classification

Used by enterprise applications to determine the legal age group of the user.

   Type: legalAgeGroupClassification

license_assignment_states

State of license assignments for this user. Also indicates licenses that are directly assigned or the user inherited through group memberships.

   Type: list[licenseAssignmentState]

mail

The SMTP address for the user, for example, jeff@contoso.com.

   Type: str

mail_nickname

The mail alias for the user.

   Type: str

mailbox_settings

Settings for the primary mailbox of the signed-in user.

   Type: MailboxSettings

mobile_phone

The primary cellular telephone number for the user.

   Type: str

my_site

The URL for the user’s site.

   Type: str

object_id

The unique identifier for the user.

   Type: str

office_location

The office location in the user’s place of business.

   Type: str

on_premises_sam_account_name

Contains the on-premises samAccountName synchronized from the on-premises directory.

   Type: str

other_mails

A list of other email addresses for the user; for example: [”bob@contoso.com”, “Robert@fabrikam.com”].

   Type: list[str]

password_policies

Specifies password policies for the user.

   Type: str

password_profile

Specifies the password profile for the user.

   Type: passwordProfile

past_projects

A list for the user to enumerate their past projects.

   Type: list[str]

postal_code

The postal code for the user’s postal address.

   Type: str

preferred_data_location

The preferred data location for the user.

   Type: str

preferred_language

The preferred language for the user. The preferred language format is based on RFC 4646.

   Type: str

preferred_name

The preferred name for the user. Not Supported. This attribute returns an empty string.

   Type: str

provisioned_plans

The plans that are provisioned for the user..

   Type: list[provisionedPlan]

proxy_addresses

For example: [“SMTP: bob@contoso.com”, “smtp: bob@sales.contoso.com”].

   Type: list[str]

responsibilities

A list for the user to enumerate their responsibilities.

   Type: list[str]

schools

A list for the user to enumerate the schools they attended

   Type: list[str]

show_in_address_list

Represents whether the user should be included in the Outlook global address list.

   Type: bool

sign_in_sessions_valid_from

Any refresh tokens or session tokens (session cookies) issued before this time are invalid.

   Type: datetime

skills

A list for the user to enumerate their skills.

   Type: list[str]

state

The state or province in the user’s address.

   Type: str

street_address

The street address of the user’s place of business.

   Type: str

surname

The user’s surname (family name or last name).

   Type: str

type

The type of the user.

   Type: str

usage_location

A two-letter country code (ISO standard 3166).

   Type: str

user_principal_name

The user principal name (UPN) of the user. The UPN is an Internet-style sign-in name for the user based on the Internet standard RFC 822.

   Type: str

user_type

A string value that can be used to classify user types in your directory.

   Type: str