Home » excel » excel – Correct permissions required for accessing Workbook object through Microsoft Graph

excel – Correct permissions required for accessing Workbook object through Microsoft Graph

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying to get a Workbook object from a file in a Sharepoint document library.

According to Microsoft, Excel needs Files.Read or Files.ReadWrite (or, for Sharepoint stored files Sites.Read or Sites.ReadWrite). The Bearer token has the following scope:

"scope": "profile openid email https://graph.microsoft.com/Files.ReadWrite https://graph.microsoft.com/Sites.ReadWrite.All https://graph.microsoft.com/User.Read https://graph.microsoft.com/.default"

When I access the file through:
https://graph.microsoft.com/v1.0/sites/{{SiteId}}/drives/{{DriveId}}/root:/{{FilePath}}

I get a file object as expected.

When I try:

https://graph.microsoft.com/v1.0/sites/{{SiteId}}/drives/{{DriveId}}/root:/{{FilePath}}:/workbook

I get:

{
  "error": {
    "code": "AccessDenied",
    "message": "Could not obtain a WAC access token.",
    "innerError": {
      "request-id": "52535b63-b77a-4140-b6b3-9291016c26a5",
      "date": "2019-10-08T23:35:28"
    }
  }
}

Looking around this seems to be either a transient error that was fixed (although I’ve had it for more than 12 hours) or a permissions error.

I can confirm that this can access the workbook for a file stored on my OneDrive but whay isn’t it working for Sharepoint?

What permissions am I missing? Or is this something else?

How to&Answers:

I experienced same error for both private One Drive and SharePoint document library. I was trying to open an macro enable template file .xltm. When I renamed file to .xlsm, the error stopped. I am new to using Microsoft Graph and Office 365. It looks like template files may not be supported? For my case, it had nothing to do with permission but the file name itself.

  • ExcelFile.xlsm – worked
  • ExcelFile.xlsx – worked
  • ExcelFile.xltm – could not obtain a WAC access token error