问题
Using graph explorer, I want to get data from Excel file from SharePoint site
From Onedrive (for business) this works: graph.microsoft.com/beta/me/drive/root:/Map1.xlsx:/workbook/worksheets
From SharePoint site doesn't: graph.microsoft.com/beta/sharepoint:/MyFabulousSite/MyDocLib/Map1.xlsx:/Workbook/worksheets Response:
Status Code: 400
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'Workbook'.",
"innerError": {
"request-id": "160a545b-66b8-44fc-92b7-f2b327824b84",
"date": "2017-01-25T16:20:02"
}
}
}
Tried this as well, didn't work either: graph.microsoft.com/beta/sharePoint/sites/ce33044e-6360-4630-9c5f-afad46f88333,cb1e4d7e-24be-433c-a874-12551cdd3348/drives/b!TBQzzmBjMEacX6-tRviDM3FNHsu-JxxDqHQSVRzdM0hfFOUPQwasQb407ORQaT2q/root:/Map1.xlsx:/workbook/worksheets Response:
Status Code: 500
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.UnknownError",
"message": "Onbekende fout",
"innerError": {
"request-id": "cec7663e-b708-4887-8d82-87d59fb15a2b",
"date": "2017-01-25T16:16:58"
}
}
}
Guess I'm closer using the last request, but still can't figure out the details.
Update:
Moving my Excel file to the root site in the default library, I'm able to request the worksheets using the following url: graph.microsoft.com/beta/sharePoint/site/drive/root:/Test.xlsx:/workbook/worksheets
回答1:
There are couple of issues as far as I see.
- GET /sharePoint/sites only returns the default site. So you have to do an additional call to get to the site in question using sharePoint/sites/{id}.
- When you use full SharePoint based "path" in the URL, the Excel API path /workbook is not being recognized.
So, as a workaround you have to navigate through the site id and drive in the URL. Until the issue is fixed, you can't use the full site Sharepoint path to get to the Excel file and use Excel API.
Workaround:
For Issue #1. You'd have to first use GET /sharePoint:/{path}:/ where {path} is the path to the site (not the file or folder) and get the site id property.
Example:
GET https://graph.microsoft.com/beta/sharepoint:/exceltest:/?$select=id
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#baseItem",
"@odata.type": "#microsoft.graph.site",
"id": "48d4a189-be5d-497a-9a6d-b971db377a5c,3a201b6c-798f-4e6a-a805-9e67fdf1c8ce"
}
For #2. Now use the id being returned to go to the drive where the file is located by using one of the following:
GET /sharePoint/sites/{id}/drive/root/items/{fileId}/workbook
GET /sharePoint/sites/{id}/drive/root:/{file-path}:/workbook
GET /sharePoint/sites/{id}/drives/{driveId}/root/items/{fileId}/workbook
GET /sharePoint/sites/{id}/drives/{driveId}/root:/{file-path}:/workbook
I'm able to access Excel API with this workaround using my developer tenant. Please let me know if this doesn't work for you.
来源:https://stackoverflow.com/questions/41854660/get-workbook-from-sharepoint-site-using-microsoft-graph-beta