Skip to content

Microsoft 365 - Sharepoint

Interact and perform various operations through a Microsoft 365 account. Download, upload, and manage files and items easily via the BotCity plugin for OneDrive/Sharepoint.

Important

Support for the Sharepoint service is included in the OneDrive plugin. Therefore, the same package is used.

The operations with the items are done the same way; the only difference is how the drive will be accessed.

See more details in OneDrive plugin documentation.

Warning

To be able to use this plugin, you need to have a Microsoft 365 account with a properly created and configured project.

After creating a project, you need to complete the authentication process through the Microsoft 365 Credentials plugin.

For more details, see the previous sections:

Installation

pip install botcity-ms365-onedrive-plugin

Importing the Plugin

After you installed this package, the next step is to import the package into your code and start using the functions.

from botcity.plugins.ms365.onedrive import MS365OneDrivePlugin

Setting the service account

As mentioned above, in order to use the OneDrive/Sharepoint plugin, it is necessary to perform the account authentication process through the Microsoft 365 Credentials plugin.

With the credentials plugin instance obtained, let's use it to instantiate the plugin.

from botcity.plugins.ms365.credentials import MS365CredentialsPlugin, Scopes
from botcity.plugins.ms365.onedrive import MS365OneDrivePlugin

# Instantiate the Credentials plugin
service = MS365CredentialsPlugin(
    client_id='<APPLICATION ID>',
    client_secret='<SECRET VALUE>',
)
service.authenticate(scopes=[Scopes.BASIC, Scopes.FILES_READ_WRITE_ALL, Scopes.SITES_READ_WRITE_ALL])

Tip

To use the Sharepoint service, in addition to adding the scope Scopes.FILES_READ_WRITE_ALL referring to the permission Files.ReadWrite.All, it is also necessary to include the scope Scopes.SITES_READ_WRITE_ALL referring to the permission Sites.ReadWrite.All of the project.

See more details about scopes and permissions at this link.

Getting a Sharepoint site reference

The first step to accessing a Sharepoint document library is to configure the site that will be used as a reference.

When instantiating the plugin, we can pass some specific information about the site we are trying to access as a parameter.

After that, we can access the site's default document library (drive).

Tip

When entering the path to the site, include sites/ at the beginning of the path, followed by the exact name of the site.

In most cases, this path should be passed in the following format: sites/{site_name}.

from botcity.plugins.ms365.credentials import MS365CredentialsPlugin, Scopes
from botcity.plugins.ms365.onedrive import MS365OneDrivePlugin

# Instantiate the Credentials plugin
service = MS365CredentialsPlugin(
    client_id='<APPLICATION ID>',
    client_secret='<SECRET VALUE>',
)
service.authenticate(scopes=[Scopes.BASIC, Scopes.FILES_READ_WRITE_ALL, Scopes.SITES_READ_WRITE_ALL])

# Instantiating the plugin with Sharepoint information
sharepoint = MS365OneDrivePlugin(
    service_account=service,
    use_sharepoint=True,
    host_name="yourcompany.sharepoint.com",
    path_to_site="sites/Site-To-Access"
)

If it is necessary to perform the operations using the drive of another specific site, you can easily configure the reference to the new site.

sharepoint.set_sharepoint_site(
    host_name="yourcompany.sharepoint.com",
    path_to_site="sites/TestSite2"
)

Managing files

With the Sharepoint service correctly configured, performing operations with files and folders is possible.

These operations are based on OneDrive functionalities. Therefore, the same plugin methods can be used.

See more details about operations with files and folders by accessing the OneDrive plugin documentation.