I read some of the questions that were asked pertaining to the same issue I'm having, but none of the answers helped.
I am trying to read or get the cell data values of an excel file (.xlsx) stored in a SharePoint site. I've already granted the following permissions, File.Read.All and Site.Read.All.
When I try to run the query below on MS Graph Explorer, I get 'Access Denied'. I have the site-id and list-id populated in my query but not shown here.
https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/3/driveItem/workbook/worksheets/usedRange
Response Preview
{
"error": {
"code": "AccessDenied",
"message": "Could not obtain a WAC access token.",
"innerError": {
"date": "2021-03-03T17:47:01",
"request-id": "ccb9aa2e-ef69-4834-802c-f71d43ee1b78",
"client-request-id": "c478..."
}
}
}
This had me scratching my head but I am finally able to access and operate on my excel file over SharePoint. I was accessing the excel file incorrectly.
I used the query below to get all the sites, including root level and sub sites:
https://graph.microsoft.com/v1.0/sites?search=*
as using the one below didn't list the site I needed:
https://graph.microsoft.com/v1.0/sites/root
Because my excel file is within a folder on that site, I need to provide the list-item-id as the folder is an item of the site. Then, I am able to access the folder as a drive and use root to provide the path to the excel file from the folder's root directory. Finally, do whatever operation needed to the workbook.
.../v1.0/sites/{site-id}/lists/{list-item-id}/drive/root:/{path-to-file}:/workbook/worksheets/{sheet-name or sheet-id}/usedRange
References: