Onedrive-api-docs: GET file content not working

Created on 9 Dec 2016  Â·  16Comments  Â·  Source: OneDrive/onedrive-api-docs

When I make call to GET file meta-data it works

curl -X GET -H "Authorization: Bearer ey.." "https://myspo.sharepoint.com/sites/zz/Non-default_Site/_api/v2.0/drives/b!ksxxx/items/014BVTELOUD3ILMS7M2ZEIJW4GUGQH3W25"

But GET file content does not. I am getting 404.
curl -X GET -H "Authorization: Bearer ey.." "https://myspo.sharepoint.com/sites/zz/Non-default_Site/_api/v2.0/drives/b!ksxxx/items/014BVTELOUD3ILMS7M2ZEIJW4GUGQH3W25/content"

Anyone else seeing this issue?

Most helpful comment

Actually, I'm seeing some similar reports on StackOverflow now which are suggesting that, if you're providing the Authorization header when you access the download.aspx URL it is now causing issues. Can you attempt your scenario WITHOUT providing this header and see if that helps.

All 16 comments

Can you provide the value of the request-id and Date response headers? We'll see if we can pull up more details of the failure.

@ificator here it is -
request-id →0264bf9d-d067-2000-97ef-51163b088425
Correlation ID: 0264bf9d-d067-2000-97ef-51163b088425
Date →Fri, 09 Dec 2016 14:53:40 GMT

@ificator If it helps here is the series of API calls we are doing

First using resourceAppId from application manifest.json - OAuth access token and refresh token are generated.

App Permissions
Office 365 SharePoint Online - Delegated Permissions
Read and Write User files
Read user files
Read and write items and lists in all site collections

Microsoft Graph - Delegated Permissions
Sign in and read user profile

Windows Azure Active Directory - Delegated Permissions
Sign in and read user profile

Accessing Content

  1. Using refreshToken from above step Call Discovery service https://api.office.com/discovery/v2.0/me/services with ResourceId = https://api.office.com/discovery/. Get serviceResourceId for serviceId = O365_SHAREPOINT and capability = RootSite. serviceResourceId will be URI for sharepoint site.
  2. Using accessToken step 1 - Check if able to connect by doing OAuth call with resource = share point site URI
  3. Using accessToken step 1 - Get OneDrive Item Content by path - https://someSPsite.sharepoint.com/_api/v2.0/drive/items/root:/Book.xlsx:/content or
    Get OneDrive Item Content by Item-Id - https://someSPsite.sharepoint.com/_api/v2.0/drive/items/01WWEXMHB2ZAMPG3LKFZB2GJTXR4K6PJ2P/content are not working.

Hi Brad @ificator can this happen because we are using incorrect resourceAppId from manifest.json?

If you have access to the metadata then your configuration should be fine. I managed to pull some logs and it does indicate a permission issue, but since the metadata was accessible that obviously shouldn't be the case. Can you share an example URL that was returned when the /content request issued the redirect? Feel free to remove the hostname + expiration query parameter to invalidate the URL, but please leave the rest of the data alone.

Actually, I'm seeing some similar reports on StackOverflow now which are suggesting that, if you're providing the Authorization header when you access the download.aspx URL it is now causing issues. Can you attempt your scenario WITHOUT providing this header and see if that helps.

Raw HTTP Request
URL = https://myspo.sharepoint.com/sites/QE/Non-default_Site1/_api/v2.0/drives/b!k1Gww4c-DkSAccxcKscnG4u5nMfgLoRGoR0DLjxtEAepix2YOnQqS7olNC6DibFg/items/014BVTELOUD3ILMS7M2ZEIJW4GUGQH3W25/content

GET /sites/QE/Non-default_Site1/_api/v2.0/drives/b!k1Gww4c-DkSAccxcKscnG4u5nMfgLoRGoR0DLjxtEAepix2YOnQqS7olNC6DibFg/items/014BVTELOUD3ILMS7M2ZEIJW4GUGQH3W25/content HTTP/1.1
cache-control: no-cache
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhb...
User-Agent: PostmanRuntime/3.0.5
Accept: /
Host: mysharepointonline.sharepoint.com
accept-encoding: gzip, deflate
Connection: close

Raw HTTP Response
HTTP/1.1 302 Found
Cache-Control: private, max-age=0
Content-Type: application/octet-stream
Expires: Fri, 25 Nov 2016 21:43:12 GMT
Last-Modified: Sat, 10 Dec 2016 21:43:12 GMT
Location: https://myspo.sharepoint.com/sites/QE/Non-default_Site1/_layouts/15/download.aspx?guestaccesstoken=7...2bBqjayUQTqK4uM%3d&docid=0b6d01ed4ec4b48d684db86a1a07ddb5d&expiration=2016-12-10T22%3a43%3a13.000Z&userid=9&authurl=True&NeverAuth=True
Server: Microsoft-IIS/8.5
X-SharePointHealthScore: 0
X-SP-SERVERSTATE: ReadOnly=0
ODATA-VERSION: 4.0
X-Download-Options: noopen
Content-Disposition: attachment
SPClientServiceRequestDuration: 76
SPRequestDuration: 126
X-AspNet-Version: 4.0.30319
SPRequestGuid: d7cdbf9d-b04f-2000-4501-5bf2d75b0539
request-id: d7cdbf9d-b04f-2000-4501-5bf2d75b0539
Strict-Transport-Security: max-age=31536000
X-FRAME-OPTIONS: SAMEORIGIN
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 16.0.0.6001
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Date: Sat, 10 Dec 2016 21:43:12 GMT
Content-Length: 0
Connection: Close

Redirect Request
https://myspo.sharepoint.com/sites/QE/Non-default_Site1/_layouts/15/download.aspx?guestaccesstoken=7kGu2eSXdQI...4uM%3d&docid=0b6d01ed4ec4b48d684db86a1a07ddb5d&expiration=2016-12-10T22%3a43%3a13.000Z&userid=9&authurl=True&NeverAuth=True

Raw HTTP Request
GET /sites/QE/Non-default_Site1/_layouts/15/download.aspx?guestaccesstoken=7kGu2eSXdQIc4vfKX7rSw636RuAUt%2bBqjayUQTqK4uM%3d&docid=0b6d01ed4ec4b48d684db86a1a07ddb5d&expiration=2016-12-10T22%3a43%3a13.000Z&userid=9&authurl=True&NeverAuth=True HTTP/1.1
cache-control: no-cache
Postman-Token: c437ff1e-c9b1-4685-bcd0-f15a46346bba
Authorization: Bearer eyJ..Q
User-Agent: PostmanRuntime/3.0.5
Accept: /
accept-encoding: gzip, deflate
referer: https://myspo.sharepoint.com/sites/QE/Non-default_Site1/_api/v2.0/drives/b!k1Gww4c-DkSAccxcKscnG4u5nMfgLoRGoR0DLjxtEAepix2YOnQqS7olNC6DibFg/items/014BVTELOUD3ILMS7M2ZEIJW4GUGQH3W25/content
Host: myspo.sharepoint.com
Connection: close

Raw HTTP Response
HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/8.5
X-SharePointHealthScore: 0
SharePointError: 0
X-AspNet-Version: 4.0.30319
SPRequestGuid: d7cdbf9d-207f-2000-cdd6-e9d6a8f7360c
request-id: d7cdbf9d-207f-2000-cdd6-e9d6a8f7360c
Strict-Transport-Security: max-age=31536000
SPRequestDuration: 179
SPIisLatency: 3
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 16.0.0.6001
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Date: Sat, 10 Dec 2016 21:43:12 GMT
Content-Length: 14394
Connection: Close

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:o="urn:schemas-microsoft-com:office:office" lang="en-us" dir="ltr">
<head><meta name="GENERATOR" content="Microsoft SharePoint" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Expires" content="0" /><meta http-equiv="X-UA-Compatible" content="IE=8"/><meta name="ROBOTS" content="NOHTMLINDEX" /><title>
Error

...
Correlation ID: d7cdbf9d-207f-2000-cdd6-e9d6a8f7360c

@ificator yes that worked

curl -H 'cache-control: no-cache' -H 'User-Agent: PostmanRuntime/3.0.5' -H 'Accept: /' -H 'accept-encoding: gzip, deflate' -H 'referer: https://myspo.sharepoint.com/sites/QE/Non-default_Site1/_api/v2.0/drives/b!k1Gww4c-DkSAccxcKscnG4u5nMfgLoRGoR0DLjxtEAepix2YOnQqS7olNC6DibFg/items/014BVTELOUD3ILMS7M2ZEIJW4GUGQH3W25/content' -H 'Host: myspo.sharepoint.com' 'https://myspo.sharepoint.com/sites/QE/Non-default_Site1/_layouts/15/download.aspx?guestaccesstoken=7kGu2eSXdQIc...%3D&docid=0b6d01ed4ec4b48d684db86a1a07ddb5d&expiration=2016-12-10T22%3A43%3A13.000Z&userid=9&authurl=True&NeverAuth=True'

HTTP Response
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/plain
Content-Encoding: gzip
Accept-Ranges: bytes
ETag: "{B6D01ED4-EC4B-48D6-84DB-86A1A07DDB5D},10"
Vary: Accept-Encoding
Server: Microsoft-IIS/8.5
X-SharePointHealthScore: 0
X-Download-Options: noopen
Content-Disposition: attachment;filename="Non_Default_File_renamed.txt"
X-AspNet-Version: 4.0.30319
SPRequestGuid: 8ccebf9d-f0a1-2000-cdd6-efffbef565db
request-id: 8ccebf9d-f0a1-2000-cdd6-efffbef565db
Strict-Transport-Security: max-age=31536000
X-FRAME-OPTIONS: SAMEORIGIN
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 16.0.0.6001
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Date: Sat, 10 Dec 2016 21:55:35 GMT
Transfer-Encoding: chunked
Proxy-Connection: Close

File name to rename

Thanks for the confirmation - this vastly reduces the scope of code we need to consider to figure out what's going on :).

Thanks a bunch Brad @ificator for confirming.

I can confirm that the error also occurs when trying to download the file via the "items" REST Endpoint using the Item ID and Auth header (as implemented in the Python SDK).

I also encountered this with OneDrive for Business (single user). OneDrive Personal does not seem to have any issues. OneDrive for Business (with admin token) either.
Removing the Authorization header from the download URL does fix the issue.

Can everyone that was seeing this issue confirm if it has been resolved? We threw the switch on a related code change that seems to bypass the issue so hopefully things are back to normal now.

Its working for me!

The fix seems to be working. Thanks.

Thanks for confirming - I'm going to close this issue. Please feel free to reactivate if you see issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

indigane picture indigane  Â·  9Comments

ishansaxena1 picture ishansaxena1  Â·  3Comments

marcreicher picture marcreicher  Â·  3Comments

geoffrey-mantel picture geoffrey-mantel  Â·  6Comments

atkinchris picture atkinchris  Â·  6Comments