3
votes

I am looking in to Microsoft Graph for the fist time. I am calling https://graph.microsoft.com/beta/me/drive/items/root:/STWTest.xlsx:/workbook/ and getting back the following response:

{
    "error": {
        "code": "AccessDenied",
        "message": "Could not obtain a WAC access token.",
        "innerError": {
            "request-id": "28dc972e-b8ce-4b5c-bfbe-2bd29094c878",
            "date": "2019-06-13T08:35:23"
        }
    }
}

Any ideas on how to resolve this error?

2

2 Answers

2
votes

I know that the OP already answered their own question, but in my case the solution was different.

I was simply using the wrong DriveItem (ie file) id (from the wrong Drive).

If you are using Teams and are working with the files inside the embedded SharePoint sites, here is one method for obtaining (or double-checking) the necessary ids:

  1. Groups (~=Teams) you are a member of (copy the id field of the Team you want from the result of this command): https://graph.microsoft.com/v1.0/me/transitiveMemberOf/microsoft.graph.group
  2. Channels of the Team (replace {team-id} in the below url, and copy the id field from the result): https://graph.microsoft.com/v1.0/teams/{team-id}/channels
  3. Sharepoint site associated with the channel (copy the parentReference.driveId field (the root of the SharePoint) and the id field (the directory that has the same name as the channel)): https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/filesFolder
  4. Contents of the Sharepoint directory for the channel (copy the id field (DriveItem id) of the file (or directory) you want): https://graph.microsoft.com/v1.0/drives/{parentReference.driveId}/items/{channel-directory-id}/children
  5. If you need to go into subdirectories, replace {channel-directory-id} in the above url with the id of the subdirectory you want to explore, to obtain its own children, and repeat as needed.

You can now build urls like: https://graph.microsoft.com/v1.0/drives/{parentReference.driveId}/items/{driveitem-id}/workbook/worksheets/My%20Sheet%20Name/range(address='A1:B2')

0
votes

After working on this for quite some time it seems my permissions were set wrong. For future reference go to the Microsoft documentation and check the permissions section at the top of the page.