Skip to content

OneDrive/SharePoint — Connect

Type: msfiles-connect  ·  Package: OneDrive / SharePoint v1.0.5  ·  Output: ZoanMicrosoftFilesSession

Opens an authenticated session with OneDrive or SharePoint through Microsoft Graph. It is the starting point of the package: the file activities (upload, download, list, move…) and the SharePoint list activities work on this session.

It authenticates with a Microsoft 365 OAuth connection from Zoan Cloud and resolves the drive to work on. It can be used in two ways:

  • With body: the activities you place inside inherit the session automatically; when the block ends, it closes on its own (also if an activity in the block fails).
  • Without body: it returns the session as output; store it in a variable, pass it through session to the other activities and close it with Close.

Step by step:

  1. It gets the connection’s token. The session keeps using that token until it is closed (it is not renewed); for processes longer than an hour, open the session in blocks.
  2. If you do not give driveId, it asks Microsoft Graph for the default drive: the OneDrive of the connection’s account or, with mailbox, that user’s. If you give driveId, it is used as is, without checking it.
  3. It keeps siteId for the list activities. It is not validated here: a wrong site shows up as an error in the first list activity.
ParameterTypeDefaultDescription
credentialcredential—Zoan Cloud Microsoft 365 OAuth connection, referenced by its key name: credential("m365-operations").
ParameterTypeDefaultDescription
mailboxstring—User (email or UPN) whose OneDrive is used when no driveId is given. Omit it to use the account that authorized the connection. Required if the credential holds an app-only token.
driveIdstring—ID of the files drive. When omitted, the OneDrive of the account (or of mailbox). Use the ID of a SharePoint document library to work with its files.
siteIdstring—SharePoint site ID (contoso.sharepoint.com,<guid>,<guid>). Only the list activities need it.

Activities to run inside the session. They inherit the session automatically and, when they finish, the session is closed.

Returns a ZoanMicrosoftFilesSession. It exposes DriveId (the resolved drive), SiteId (or null) and Account (the name of the OneDrive’s owner, the given mailbox or me). With body you do not need the output (the session is inherited) and Connect returns nothing. Without body, assign it to a variable and pass it as session to the other activities.

MessageCause and fix
Credential 'm365-operations' could not be resolved. Verify it exists in Zoan Automation and that there is an active session.There is no credential or connection with that key name in the environment, or the robot has no Zoan Cloud session. Check the key name (not the display name) and that the connection is Connected.
'credential' does not contain a valid access_token. Check the Microsoft 365 OAuth Connection in Zoan Cloud.The credential resolved to an empty value. Reconnect the connection in Zoan Cloud.
InvalidAuthenticationToken (Microsoft Graph, 401)The credential value is not a token: this usually happens when writing "m365-operations" instead of credential("m365-operations").
Could not resolve the user's drive. Provide 'driveId'.Microsoft Graph returned no drive for the account or mailbox. Give driveId.
itemNotFound / ResourceNotFound (Microsoft Graph, 404)The mailbox does not exist or has no OneDrive provisioned.
accessDenied (Microsoft Graph, 403)The connection is not allowed to read that user’s drive (missing Files.ReadWrite.All).

To retry on transient Microsoft 365 failures, wrap the block in Retry; to handle the error and continue, in Try / Catch.

OneDrive/SharePoint — Connect credential = credential("m365-operations")
└─ body:
OneDrive/SharePoint — Upload path = "C:\reports\today.pdf" destination = "Reports/today.pdf" → output: uploaded
OneDrive/SharePoint — Share id = uploaded["id"] email = "customer@mail.com" role = view

Files and lists of the same SharePoint site:

OneDrive/SharePoint — Connect credential = credential("m365-operations") siteId = siteId driveId = libraryId
└─ body:
OneDrive/SharePoint — List files → output: documents
SharePoint — Get list items list = "Requests" → output: requests