2
votes

I'm trying to use the Microsoft Graph API to List Children by Getting access without a user

I have built my URL as you would expect:

https://graph.microsoft.com/v1.0/edffcd1c-e5b2-42f2-b554-XXXXXXXXX/drive/root/children

Where edffcd1c-e5b2-42f2-b554-XXXXXXXXX is the user ID of whom I'm trying to list the files.

Yet when I call this I get an empty result every time:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drive/root/children",
    "value": []
}

Why is that?

UPDATE: It seems that this API is only returning files from the Sharepoint account... not the OneDrive account. I already have access to the Sharepoint files from the Sharepoint API's themselves. Is there a way to get OneDrive files from the Microsoft Graph API?

This URL https://dev.onedrive.com/README.htm seems to state that we should be able to do this.

4
Have you attempted to use the userPrincipalName instead of id? For example: /users/[email protected]/drive/root/children.Marc LaFleur
yeah that just makes it throw an error "resource not found for the segment". I talked to microsoft ... this api only supports sharepoint files through app-only user i guess. total garbageNicholas DiPiazza

4 Answers

4
votes

Is there a way to get OneDrive files from the Microsoft Graph API?

Yes, there is: you must use the scope Files.Read.All or Files.ReadWrite.All

then, your requests to /drive/root/children will no longer return an empty array.

1
votes

I just had a typo in the User:

https://graph.microsoft.com/v1.0/edffcd1c-e5b2-42f2-b554-XXXXXXXXX/drive/root/children

was supposed to be

https://graph.microsoft.com/v1.0/users('edffcd1c-e5b2-42f2-b554-XXXXXXXXX')/drive/root/children

1
votes

You can also use this endpoint https://graph.microsoft.com/v1.0/me/drive/root/children

and pass authorization header Bearer Token

1
votes

There are two things:

1) First check if the user has given the permission for

Files.Read.All or Files.ReadWrite.All

2) The following endpoint didn't work for business account

/drive/root/children

I changed it to

/drives/{drive_id}/root/children

and it worked fine. Please check.