I'm trying to retrieve the contents of my OneDrive for Business folder, and the content of an Excel document within using the Javascript SDK. When I test the request in Graph Explorer, it correctly retrieves folder or file content. When I make the same request to the Javascript API my root folder is empty and files cannot be retrieved even by ID (404 error).
For the most part I followed the getting started tutorial, just changed the request to gather files instead of calendar events. I have set up an app in Azure and provisioned it with Microsoft Graph permissions for User.Read,Files.Read,Files.Read.All and Files.Read.Selected. Other settings are as per described in the Register the app tutorial.
In Graph Explorer:
https://graph.microsoft.com/v1.0/me/drive/root/children
https://graph.microsoft.com/v1.0/me/drive/items/{item_ID}/workbook/tables('1')/rows
Correctly returns contents of the root, and the contents of an Excel sheet respectively.
But when I try that in JavaScript:
const graphClient = MicrosoftGraph.Client.initWithMiddleware({ authProvider });
let request = await graphClient.api("/me/drive/root/children").get();
console.log(request);
(The request URL goes out as: https://graph.microsoft.com/v1.0/me/drive/root/children )
The result is:
@odata.context: "https://graph.microsoft.com/v1.0/$metadata#users('{my user ID}')/drive/root/children"
value: Array(0)
I have tried:
- Referring to drive by its ID (same result)
- Referencing a file by ID (404 error)
- Retrieving my user data (Correctly retrieved)
- Provisioned app with
Sites.Read.Allthen modifying the request to go via SharePoint storage"/sites/" + siteId + "/drives/" + driveId + "/root/children"(same result)
I suspect I am just structuring my request incorrectly, have missed something vital in the App provisioning or just don't understand something about where OneDrive for Business keeps its files. I've followed every similar question I've found here on Stack Overflow but nothing suggested changed my result.