RPA.MSGraph

Exchanges the OAuth authorization URL obtained from Generate OAuth Authorization URL for an access token. This library maintains the user access token for current requests and returns the refresh token to be stored in a secure location (e.g., the Robocorp Control Room Vault).

Arguments

ArgumentTypeDefault valueDescription
authorization_urlstrnullThe full URL retrieved by the user after completing authorization to Microsoft.
param authorization_url:
 The full URL retrieved by the user after completing authorization to Microsoft.
return:A refresh token which should be stored securely for future sessions.

Configures the MS Graph client. If a refresh token is known, it can be provided to obtain a current user token to authenticate with. A new refresh token is returned if one is provided.

Arguments

ArgumentTypeDefault valueDescription
client_idstrnullApplication client ID.
client_secretstrnullApplication client secret.
refresh_tokenstr, NoneNoneAuthorization refresh token obtained from prior OAuth flows.
redirect_uristr, NoneNoneMust be provided with client ID and client secret if not using the default.
param client_id:
 Application client ID.
param client_secret:
 Application client secret.
param refresh_token:
 Authorization refresh token obtained from prior OAuth flows.
param redirect_uri:
 Must be provided with client ID and client secret if not using the default.
return:A new refresh token if one was provided, or None.

Creates a sharepoint list and returns the instance.

Arguments

ArgumentTypeDefault valueDescription
list_datadictnullDictionary with the data for the new list.
siteSitenullSite instance obtained from Get Sharepoint Site.
param list_data:
 Dictionary with the data for the new list.
param site:Site instance obtained from Get Sharepoint Site.
return:SharePoint List that was created.

SharepointList objects have additional properties that can be accessed with dot-notation, see examples below.

Downloads a file from Onedrive.

Arguments

ArgumentTypeDefault valueDescription
target_fileFile, strnullDriveItem or file path of the desired file.
to_pathstr, Path, NoneNoneDestination folder of the downloaded file, defaults to the current directory.
namestr, NoneNoneNew name for the downloaded file, with or without extension.
resourcestr, NoneNoneName of the resource if not using default.
driveDrive, str, NoneNoneA Drive object or Drive ID as a string. If not provided, will use the default drive.

The downloaded file will be saved to a local path.

param target_file:
 DriveItem or file path of the desired file.
param to_path:Destination folder of the downloaded file, defaults to the current directory.
param name:New name for the downloaded file, with or without extension.
param resource:Name of the resource if not using default.
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
return:Path to the downloaded file.

Downloads file from SharePoint.

Arguments

ArgumentTypeDefault valueDescription
target_fileFile, strnullDriveItem or file path of the desired file.
siteSitenullSite instance obtained from Get Sharepoint Site.
to_pathstr, Path, NoneNoneDestination folder of the downloaded file, defaults to the current directory.
namestr, NoneNoneNew name for the downloaded file, with or without extension.
driveDrive, str, NoneNoneA Drive object or a Drive ID as a string.

The downloaded file will be saved to a local folder.

param target_file:
 DriveItem or file path of the desired file.
param site:Site instance obtained from Get Sharepoint Site.
param to_path:Destination folder of the downloaded file, defaults to the current directory.
param name:New name for the downloaded file, with or without extension.
param drive:A Drive object or a Drive ID as a string.
return:Path to the downloaded file.

Downloads a folder from OneDrive with all of its contents, including subfolders.

Arguments

ArgumentTypeDefault valueDescription
target_folderFolder, strnullDriveItem or path of the desired folder.
to_pathstr, Path, NoneNoneDestination folder where the download will be saved to, defaults to the current directory.
resourcestr, NoneNoneName of the resource if not using default.
driveDrive, str, NoneNoneA Drive object or Drive ID as a string. If not provided, will use the default drive.

Caution when downloading big folder structures. The downloaded folder will be saved to a local path.

param target_folder:
 DriveItem or path of the desired folder.
param to_path:Destination folder where the download will be saved to, defaults to the current directory.
param resource:Name of the resource if not using default.
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
return:Path to the downloaded folder.

Returns a list of files found in OneDrive based on the search string. If a folder is not specified, the search is done in the entire drive and may include items that were shared with the user. It is possible to pass root as the target folder in order to avoid this behavior.

Arguments

ArgumentTypeDefault valueDescription
search_stringstrnullString used to search for file in Onedrive. Values may be matched across several fields including filename, metadata, and file content.
target_folderFolder, str, NoneNoneFolder where to search for files.
include_foldersbool, NoneFalseBoolean indicating if should return folders as well.
resourcestr, NoneNoneName of the resource if not using default.
driveDrive, str, NoneNoneA Drive object or Drive ID as a string. If not provided, will use the default drive.

The files returned are DriveItem objects and they have additional properties that can be accessed with dot-notation, see List Files In Onedrive Folder for details.

param search_string:
 String used to search for file in Onedrive. Values may be matched across several fields including filename, metadata, and file content.
param target_folder:
 Folder where to search for files.
param include_folders:
 Boolean indicating if should return folders as well.
param resource:Name of the resource if not using default.
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
return:List of DriveItems found based on the search string.

Generates an authorization URL which must be opened by the user to complete the OAuth flow. If no scopes are provided, the default scope is used which is all scopes defined in the Get Scopes keyword.

Arguments

ArgumentTypeDefault valueDescription
client_idstr, NoneNoneApplication client ID.
client_secretstr, NoneNoneApplication client secret.
redirect_uristr, NoneNoneCan be provided with client ID and client secret if not using the default.
scopeslist, NoneNoneA list of scopes in the form required by the API. Use the helper function Get scopes.
param client_id:
 Application client ID.
param client_secret:
 Application client secret.
param redirect_uri:
 Can be provided with client ID and client secret if not using the default.
param scopes:A list of scopes in the form required by the API. Use the helper function Get scopes.
return:The URL the user must follow to complete their portion of the OAuth flow.

Returns the specified drive from the specified resource. If either is not provided, defaults are returned.

Arguments

ArgumentTypeDefault valueDescription
resourcestr, NoneNoneName of the resource if not using default.
drive_idstr, NoneNoneThe Drive ID as a string.
param resource:Name of the resource if not using default.
param drive_id:The Drive ID as a string.
return:The requested Drive object.

Returns a File object from the provided drive. If a File object is provided, it is reobtained from the API.

Arguments

ArgumentTypeDefault valueDescription
driveDrive, strnullA Drive object or Drive ID as a string. If not provided, will use the default drive.
fileFile, strnull
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
param file_path:
 A File object or path as a string.

Returns a folder object from the provided drive. If a folder object is provided, it is reobtained from the API.

Arguments

ArgumentTypeDefault valueDescription
driveDrive, str, NoneNoneA Drive object or Drive ID as a string. If not provided, will use the default drive.
folderFolder, str, NoneNoneA Folder object or folder path as a string.
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
param folder:A Folder object or folder path as a string.

Returns the items on a SharePoint list as a table. The list is found by it's display name.

Arguments

ArgumentTypeDefault valueDescription
list_namestrnullDisplay name of the SharePoint list.
siteSitenullSite instance obtained from Get Sharepoint Site.
param list_name:
 Display name of the SharePoint list.
param site:Site instance obtained from Get Sharepoint Site.
return:Table or list of dicts of the items.

Returns the MS Graph object representing the currently logged in user. A User object is returned. Properties of the user can be accessed like so:

Returns the proper scope definitions based on the provided "scope helpers", which are enumerated below. You can pass none to get all scopes. Basic is included in all other scopes. The provided object can be passed to the scopes parameter when calling Generate OAuth Authorization URL.

Arguments

ArgumentTypeDefault valueDescription
scopesstrnullScopes requested. If left empty, all scopes will be returned.
  • basic
  • mailbox
  • mailbox_shared
  • message_send
  • message_send_shared
  • message_all
  • message_all_shared
  • address_book
  • address_book_shared
  • address_book_all
  • address_book_all_shared
  • calendar
  • calendar_shared
  • calendar_all
  • calendar_shared_all
  • users
  • onedrive
  • onedrive_all
  • sharepoint
  • sharepoint_dl
  • settings_all
  • tasks
  • tasks_all
  • presence
param scopes:Scopes requested. If left empty, all scopes will be returned.
return:A list of Scopes which can be passed to authorization keywords.

Returns a SharePoint site.

Arguments

ArgumentTypeDefault valueDescription
argsstrnullThe SharePoint site to retrieve, see documentation for different methods of defining the site.
resourcestr, NoneName of the resource if not using default.
param args:The SharePoint site to retrieve, see documentation for different methods of defining the site.
param resource:Name of the resource if not using default.
return:SharePoint Site instance.

There are multiple ways of retrieving a SharePoint site:

The return is of type Site and it has additional properties that can be accessed with dot-notation. See examples below.

Returns a list of files from the specified OneDrive folder.

Arguments

ArgumentTypeDefault valueDescription
target_folderFolder, str, NoneNonePath of the folder in Onedrive. If none is provided, will return files from the root of Onedrive.
include_foldersbool, NoneFalseBoolean indicating if should return folders as well.
resourcestr, NoneNoneName of the resource if not using default.
driveDrive, str, NoneNoneA Drive object or Drive ID as a string. If not provided, will use the default drive.

The files returned are DriveItem objects and they have additional properties that can be accessed with dot-notation.

param target_folder:
 Path of the folder in Onedrive. If none is provided, will return files from the root of Onedrive.
param include_folders:
 Boolean indicating if should return folders as well.
param resource:Name of the resource if not using default.
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
return:List of DriveItems in the folder.

List files in the SharePoint Site drive.

Arguments

ArgumentTypeDefault valueDescription
siteSitenullSite instance obtained from Get Sharepoint Site.
include_foldersbool, NoneFalseBoolean indicating if should return folders as well.
driveDrive, str, NoneNoneA Drive object or Drive ID as a string. If not provided, will use the default drive.
target_folderFolder, str, NoneNonePath of the folder in the Sharepoint drive. If none is provided, will return files from the root of the drive.

If the drive is not set, the default Document Library will be used. The drive can be obtained from the keyword List Sharepoint Site Drives.

The files returned are DriveItem objects and they have additional properties that can be accessed with dot-notation, see List Files In Onedrive Folder for details.

param site:Site instance obtained from Get Sharepoint Site.
param include_folders:
 Boolean indicating if should return folders as well.
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
param target_folder:
 Path of the folder in the Sharepoint drive. If none is provided, will return files from the root of the drive.
return:List of DriveItems present in the Site drive.

Get a list of Drives available in the SharePoint Site.

Arguments

ArgumentTypeDefault valueDescription
siteSitenullSite instance obtained from Get Sharepoint Site.
param site:Site instance obtained from Get Sharepoint Site.
return:List of Drives present in the SharePoint Site.

Refreshes the user token using the provided refresh_token. The user token is retained in the library and a new refresh token is returned. If no token is provided, this keyword assumes the Robocorp Vault is being used as a backend and attempts to refresh it based on that backend.

Arguments

ArgumentTypeDefault valueDescription
refresh_tokenstr, NoneNoneThe refresh token to use to refresh the session.
param refresh_token:
 The refresh token to use to refresh the session.
return:A refresh token which should be stored securely for future sessions.

Returns a list of User objects from the Active Directory based on the provided search string.

Arguments

ArgumentTypeDefault valueDescription
search_stringstrnullText to search for.
search_fieldstrdisplayNameWhere to search. Defaults to display name.
resourcestrusersName of the resource if not using default.

User objects have additional properties that can be accessed with dot-notation, see Get Me for additional details.

param search_string:
 Text to search for.
param search_field:
 Where to search. Defaults to display name.
param resource:Name of the resource if not using default.

Uploads a file to the specified OneDrive folder.

Arguments

ArgumentTypeDefault valueDescription
file_pathstrnullPath of the local file being uploaded.
target_folderFolder, str, NoneNonePath of the folder in Onedrive.
resourcestr, NoneNoneName of the resource if not using default.
driveDrive, str, NoneNoneA Drive object or Drive ID as a string. If not provided, will use the default drive.

The uploaded file is returned as a DriveItem object and it has additional properties that can be accessed with dot-notation, see List Files In Onedrive Folder for details.

param file_path:
 Path of the local file being uploaded.
param target_folder:
 Path of the folder in Onedrive.
param resource:Name of the resource if not using default.
param drive:A Drive object or Drive ID as a string. If not provided, will use the default drive.
return:The newly created DriveItem.