- Working with SharePoint API
- Authentication
- Example
- Documentation
- Authentication
- Examples
- Working with Microsoft Teams API
- Authentication
- Examples
- Installation
- Authentication
- Working with SharePoint API
- Authentication
- 1. Using a SharePoint App-Only principal (client credentials flow)
- 2. Using username and password
- 3. Using an Azure AD application (certificate credentials flow)
- 4. interactive
- Working with Outlook API
- Authentication
- Working with OneDrive and SharePoint v2 APIs
- Documentation
- Authentication
- Working with Microsoft Teams API
- Authentication
- Examples
- Working with Microsoft Onenote API
Working with SharePoint API
There are two approaches available to perform API queries:
- ClientContext class — where you target SharePoint resources such as Web , ListItem and etc (recommended)
or alternatively via method chaining (a.k.a Fluent Interface):
The list of supported APIs:
Since Outlook REST APIs are available in both Microsoft Graph and the Outlook API endpoint, the following clients are available:
- GraphClient which targets Outlook v2.0 version (preferable nowadays, refer transition to Microsoft Graph-based Outlook REST API for a details)
- OutlookClient which targets Outlook v1.0 version (not recommended for usage since v1.0 version is being deprecated.)
Authentication
ADAL Python library is utilized to authenticate users to Active Directory (AD) and obtain tokens
Example
The example demonstrates how to send an email via Microsoft Graph endpoint.
Documentation
Authentication
ADAL Python library is utilized to authenticate users to Active Directory (AD) and obtain tokens
Examples
Example: list available drives
The example demonstrates how to enumerate and print drive’s url which corresponds to list available drives endpoint
Refer OneDrive examples section for a more examples.
Working with Microsoft Teams API
Authentication
ADAL Python library is utilized to authenticate users to Active Directory (AD) and obtain tokens
Examples
Example: create a new team under a group
The example demonstrates how create a new team under a group which corresponds to Create team endpoint
The following libraries will be installed when you install the client library:
Installation
Alternatively the latest version could be directly installed via GitHub:
pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git
Authentication
For the following examples, relevant credentials can be found in the Azure Portal.
- Login to the home page of the Azure Portal
- Navigate to «Azure Active Directory» using the three bars in the top right corner of the portal
- Select «App registrations» in the navigation panel on the left
- Search for and select your relevant application
- In the application’s «Overview» page, the client id can be found under «Application (client) id»
- In the application’s «Certificates & Secrets» page, the client secret can be found under the «Value» of the «Client Secrets.» If there is no client secret yet, create one here.
Working with SharePoint API
The ClientContext client provides the support for a legacy SharePoint REST and OneDrive for Business REST APIs, the list of supported versions:
Authentication
The following auth flows are supported:
1. Using a SharePoint App-Only principal (client credentials flow)
This auth method is compatible with SharePoint on-premises and still relevant model in both SharePoint on-premises as SharePoint Online, the following methods are available:
- ClientContext.with_credentials(client_credentials)
- ClientContext.with_client_credentials(client_id, client_secret)
client_credentials = ClientCredential('','') ctx = ClientContext('').with_credentials(client_credentials)
2. Using username and password
user_credentials = UserCredential('','') ctx = ClientContext('').with_credentials(user_credentials)
3. Using an Azure AD application (certificate credentials flow)
4. interactive
to login interactively i.e. via a local browser
In Azure Portal, configure the Redirect URI of your «Mobile and Desktop application» as http://localhost .
There are two approaches available to perform API queries:
- ClientContext class — where you target SharePoint resources such as Web , ListItem and etc (recommended)
or alternatively via method chaining (a.k.a Fluent Interface):
Refer examples section for another scenarios
Working with Outlook API
The list of supported APIs:
Since Outlook REST APIs are available in both Microsoft Graph and the Outlook API endpoint, the following clients are available:
- GraphClient which targets Outlook API v2.0 version (preferable nowadays, refer transition to Microsoft Graph-based Outlook REST API for a details)
— OutlookClient which targets Outlook API v1.0 version (not recommended for usage since v1.0 version is being deprecated.)
Authentication
The Microsoft Authentication Library (MSAL) for Python which comes as a dependency is used as a default library to obtain tokens to call Microsoft Graph API.
Note: access token is getting acquired via Client Credential flow in the provided examples. Other forms of token acquisition can be found here: https://msal-python.readthedocs.io/en/latest/
But in terms of Microsoft Graph API authentication, another OAuth spec compliant libraries such as adal are supported as well.
The example demonstrates how to send an email via Microsoft Graph endpoint.
Additional examples & scenarios:
Refer to examples section for other scenarios
Working with OneDrive and SharePoint v2 APIs
Documentation
Authentication
The Microsoft Authentication Library (MSAL) for Python which comes as a dependency is used to obtain token
The example demonstrates how to enumerate and print drive’s url which corresponds to list available drives endpoint
Refer to OneDrive examples section for more examples.
Working with Microsoft Teams API
Authentication
The Microsoft Authentication Library (MSAL) for Python which comes as a dependency is used to obtain token
Examples
Example: create a new team under a group
The example demonstrates how create a new team under a group which corresponds to Create team endpoint
Refer to examples section for other scenarios
Working with Microsoft Onenote API
The library supports OneNote API in terms of calls to a user’s OneNote notebooks, sections, and pages in a personal or organization account
Example: Create a new page
The example demonstrates how to create a new planner task which corresponds to Create plannerTask endpoint:
The following libraries will be installed when you install the client library: