question

EdwinFajar-4575 avatar image
10 Votes"
EdwinFajar-4575 asked saldana-msft edited

Download Sharepoint and OneDrive files from MS Graph API returning Error 400

Previously, I have no problem when downloading Sharepoint and OneDrive files from MS Graph API using this endpoint Download the contents of a DriveItem. But since the 3rd of July 2021, I got Error 400 when downloading the file.

I tried to hit these endpoints using Application Permission and have Files.ReadWrite.All roles

GET /sites/{siteId}/drive/items/{item-id}/content
GET /users/{userId}/drive/items/{item-id}/content

And also tried to make a request directly to the URL from @microsoft.graph.downloadUrl property and got the same Error 400 result with this body.

 {
   "error": {
     "code": "invalidRequest",
     "innerError": {
       "code": "badArgument"
     },
     "message": "One of the provided arguments is not acceptable."
   }
 }

I also see something strange from the response header at docID value. Usually, it has our site id value, but this one has value like this. The 00000000-0000-0000-0000-000000000000 seems like a dummy value.

XXXXX-my.sharepoint.com_00000000-0000-0000-0000-000000000000_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

Any idea what is the cause? Is there any bug? Or I should add more property to the header?
Thanks

















sharepoint-devmicrosoft-graph-files
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EdwinFajar-4575 avatar image
0 Votes"
EdwinFajar-4575 answered MichaelHan-MSFT commented

Hi @MichaelHan-MSFT,

Like @andriejus said, we have another tenant where the download file works and there are several tenants that also didn't works.
But I just check again this morning and now the download file works. I will check again for another tenant that has the same issue before.

Thank you for your reply.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @EdwinFajar-4575,
Since this issue has been resolved, you could accept your answer to close this thread:)

0 Votes 0 ·
Martin-0841 avatar image
2 Votes"
Martin-0841 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TommyThorsen-5930 avatar image
4 Votes"
TommyThorsen-5930 answered

I have the same problem. It appeared around the same time as OP describes.

If I grab the downloadUrl, and paste it into my browser's url bar, I get the same error message. However, if I first strip out the tempauth parameter from the downloadUrl, the download succeeds (since I am logged into sharepoint in my browser, and don't strictly need the url auth).

This might indicate either a problem with generating or with parsing the JWT payload used for the tempauth parameter.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

andriejus avatar image
4 Votes"
andriejus answered andriejus edited

We have another tenant where download link returned by /content endpoint works. I tried comparing tokens received by endpoint where it works and one where it does not but besides values unique for that request, the tokens are the same.
Like @TommyThorsen-5930 mentioned, removing tempauth query parameter does allow downloading files. This is not a solution though.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
1 Vote"
MichaelHan-MSFT answered MichaelHan-MSFT converted comment to answer

Hi @EdwinFajar-4575,

Just did a test on my tenant. The endpoint to Download file works on my end. Also I could download the file with the URL from @microsoft.graph.downloadUrl property.

Let me check more about this issue.

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@andriejus, @TommyThorsen-5930 @EdwinFajar-4575,

Could you please share the error info of the failed request(Date and request id)? I would help check the log for you.

0 Votes 0 ·

Here is the last request to /content endpoint that has failed:

Date: Tue, 06 Jul 2021 09:33:48 GMT
request-id: c2bc7cfa-fe6a-4b61-b88e-9ce7b2379f00
client-request-id: c2bc7cfa-fe6a-4b61-b88e-9ce7b2379f00
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"005","RoleInstance":"AM4PEPF0000E738"}}

0 Votes 0 ·

@andriejus,

The log said: Graph got 302 from https://yourtenant.sharepoint.com//_api/v2.0/sites('<key>')/drive/items/<key>/content,

This is okay because the file server will always redirect to the preauthenticated link for downloading the file. It seems something wrong with SharePoint api.


0 Votes 0 ·

@andriejus,

Seems this works now. Could you check on your tenant?

0 Votes 0 ·
Show more comments
CathleenRaschke-7593 avatar image
2 Votes"
CathleenRaschke-7593 answered

Having the same problem when using @microsoft.graph.downloadUrl property on our production tenant.
It worked up until the last few days and it still works on our test tenant.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.