2
votes

I tried to download a file with Grpah API.

Tested with API browser, https://graph.microsoft.io/en-us/graph-explorer#

Ran following request, got list of file/folder item information,

https://graph.microsoft.com/v1.0/me/drive/root/children

And for one of the file item, I was able to get item information.

https://graph.microsoft.com/beta/me/drive/items/_an_item_id

But following returns HTTP 404.

https://graph.microsoft.com/beta/me/drive/items/_an_item_id/content

What will be the cause for this symptom?

1
Did the /content request itself 404, or did it redirect you (302) to a URL that then returned a 404?Brad
Thanks @Brad, yes, 302 returned first and then 404. And the found location is exactly the same is the "@microsoft.graph.downloadUrl" information for the File Item.Locke
@Brad, so is it because just the graph Explorer doesn't support the redirection? I have authenticated my Azure registered app with Daemon mode, got Auth-Code. I tried to download the file in 'download url' with 'Bearer' HTTP header but it says 404. How do you download a file from that link?Locke
You mentioned daemon mode, does this mean you're targeting a OneDrive for Business account with an app-only token?Brad
@Brad Not sure what's 'App-only' token but I tried "Daemon or Server Application to Web API" auth flow described here. azure.microsoft.com/en-us/documentation/articles/… Example is here github.com/Azure-Samples/active-directory-dotnet-daemon It basically uses Client Id and Client secret, that's all.Locke

1 Answers

1
votes

It is not supported to perform request to https://graph.microsoft.com/beta/me/drive/items/<itemid>/content endpoint via Graph Explorer.

The request sent to https://graph.microsoft.com/beta/me/drive/items/<itemid>/content endpoint via Grath Explorer is issued as a preflight request. The server responds with 302-Redirect but redirects are not allowed for preflighted requests due to CORS behavior.

Here is a workaround on how to download a file

The following drive item resource request:

https://graph.microsoft.com/beta/me/drive/items/<itemId>

returns @microsoft.graph.downloadUrl annotation which contains the actual link to file resource.

Once the drive item resource is retrieved, perform another GET request to url from @microsoft.graph.downloadUrl to return the actual file.