Issue: Microsoft Graph API v1.0 doesn't return the binary content of an item in an O365 group drive when specifying the correct item-id in the following Graph path:
/groups/{group-id}/drive/items/{item-id}/content
Documentation is also conflicting with '/files' parameter from Graph API Beta
https://dev.office.com/blogs/GroupsRESTAPI
Article:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_get_content
@daspek was is the correct way to get the content of a item in a groups onedrive?
@espressobeanies Getting the content of a file should be the same regardless of what Drive it's in, whether it's a group or other. The doc you linked to in the API Reference is the most up to date on how to get content.
One thing I did notice is that the call to get content does not work when using Graph Explorer. If you put it inside an actual application however it should work. In my case I did a test against a word doc and properly got back a file with the type "application/vnd.openxmlformats-officedocument.wordprocessingml.document" in the media type from the headers.
Do you have a specific file type you're trying to get that isn't working?
@JeremyKelley Yes, I'm working with .docx files and I'm only able to get back 323 bytes of the actual file. I tried setting the 'content-type' to what you have, however it didn't seem to make much difference in my output. Here's the path I'm trying:
https://graph.microsoft.com/v1.0/groups/{group-id}/drive/root/children/{filename}/content
Is anyone monitoring responses to these threads?
Jeremy is on vacation. I'm trying to find someone else who can help here @espressobeanies sorry for delay.
@espressobeanies are you seeing this for all files, or just a single one?
I assume you're seeing the 302 redirect to the download URL, and it's the download URL that's only returning 323 bytes of content? Does the Content-Length header say something different?
I'm probably going to need some more info to diagnose this. Would you mind if I emailed you?
Thanks @jthake-msft
Daspek, I'm seeing this for all the files I tried in a directory. So, I actually get the following message when I open the file in Notepad:
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="en-US">Access denied. You do not have permission to perform this action or access this resource.</m:message></m:error>
Sure, please reach out to me. Thanks.
Daspek, I made a mistake. The actual URL is:
https://{tenant}.sharepoint.com/sites/{O365_Group_Name}/_api/web/GetFileByServerRelativeUrl('/sites/{O365_Group_Name}/shared%20documents/test.txt')/$value'
The previous URL, I get no content.
@espressobeanies did this resolve your issue? if so could you close the issue below?
@jthake-msft it didn't. I tried both URL methods and they kicked back the same "Access Denied" message that I posted above
@espressobeanies thanks for the clarification. The 323-byte response you're getting is the error message, not a corrupt partial file. So that's good. The URL you're using points to a direct SharePoint REST API and is not part of Microsoft Graph. If you're using an auth token for Microsoft Graph, then that token won't work with this API, and that could be the source of your problem.
Could you try using the Graph API you linked to above (https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_get_content) instead?
Daspek, if I use the Microsoft Graph link from above, I get a file size with zero bytes and no error messages from my REST output. Using the same URL in Graph Explorer and substituting with '.../drive/items/{item-id}' or '.../drive/root:/{item-path}' from the "driveitem_get_content" API link minus the '/content' statement at the end, I can pull up metadata details about the file I'm targeting and I can mimic the same content in my REST program, so that part works. It's as soon as I request the '/content' where things stop working.
@espressobeanies, when you request /content, the server should return a 302 redirect to a download URL. if you follow the download URL, you should be able to get the content. also, in the metadata response you get back without /content, you should see a property called @microsoft.graph.downloadUrl. you can do a GET on that URL to download the file, as well. this is essentially what the /content endpoint redirects to.
Daspek, thanks for the clarification. I tested this and was referred directly to the file in Postman. I'm guessing the issue is now with my REST program.
Yep, confirmed my program wasn't able to accommodate 302 requests and that it was failing to follow the redirect. Thanks all.