2

the use case

I would like to download an excel sheet from OneDrive using the REST API

Documentation:

the documentation proposed to call this Endpoint : GET /me/drive/items/{item-id}/content

prerequisites

  1. I am correctly logged using oauth2, all other methods work such as '/me', '/me/drive/recent', '/me/drive/sharedWithMe'

  2. The granted credentials on

The error message when I call GET /me/drive/items/{item-id}/content

{
  "error": {
    "code": "itemNotFound", 
    "innerError": {
      "client-request-id": "aaaaaaa-aaaa-aaaa-aaaa-aaaaa", 
      "date": "2020-09-26T09:19:08", 
      "request-id": "aaaaa-aaaa-aaaa-aaa-aaa"
    }, 
    "message": "The specified item does not have content."
  }
}

The file exists and contains data when I call GET /me/drive/items/{item-id}

The file exists and weight : 46.272 bytes



{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('<a_username>%40hotmail.com')/drive/items/$entity", 
  "createdBy": {
    "user": {
      "displayName": "<a_name> ", 
      "id": "<a_drive_id>"
    }
  }, 
  "createdDateTime": "2020-09-27T07:29:04.893Z", 
  "eTag": "<an_eTag>", 
  "fileSystemInfo": {
    "lastAccessedDateTime": "2020-09-27T11:52:31Z"
  }, 
  "id": "<a_drive_id>!<a_sub_id>", 
  "lastModifiedBy": {
    "user": {
      "displayName": "<a_name> ", 
      "id": "<a_drive_id>"
    }
  }, 
  "lastModifiedDateTime": "2020-09-27T18:46:25.073Z", 
  "name": "a_filename.xlsx", 
  "parentReference": {
    "driveId": "<a_drive_id>", 
    "driveType": "personal"
  }, 
  "remoteItem": {
    "file": {}, 
    "fileSystemInfo": {
      "lastAccessedDateTime": "2020-09-27T11:52:31Z"
    }, 
    "id": "<an_id>!7757", 
    "name": "a_filename.xlsx", 
    "parentReference": {
      "driveId": "<an_id>", 
      "driveType": "personal"
    }, 
    "size": 46272, 
    "webUrl": "https://1drv.ms/u/<a_letter>!<a_web_url_id>"
  }, 
  "webUrl": "https://1drv.ms/u/<a_letter>!<a_web_url_id>"
}

Conclusion

Is there a bug in the implementation of the API by Microsoft ?!?

What do I do wrong?

Abdelkrim
  • 2,048
  • 5
  • 30
  • 44
  • How are you trying to call, are you testing it in Graph Explorer or in Postman or any application you are using? If you can also share the request id and timestamp it can help us. – Shiva Keshav Varma Sep 28 '20 at 15:06
  • `/me/drive/items/{item-id}` supposed to give you a long URL as `@microsoft.graph.downloadUrl` . This URL downloads the file even for anonymous visitors. Do you have this url? What does it display? – Ergec Sep 29 '20 at 13:52
  • I'm starting a bounty on this I have been stuck on the same issue for hours. @ShivaKeshavVarma I am using the Python quickstart with msal in a Flask context. id/timestamp: "date": "2022-04-18T15:38:59", "request-id": "1f573177-317e-4181-8582-61450e48069d" – Neil Apr 18 '22 at 15:41
  • Try this API call and see if it works. `me/drive/root:/{item-path}:/content` – Shiva Keshav Varma Apr 19 '22 at 02:29
  • According to the api document, I think we need to make sure the target item can be downloaded and notice if we are stopped by 302 redirection.@Neil – Tiny Wang Apr 20 '22 at 06:26

2 Answers2

1

Firstly, we need to notice that in the api document, it mentioned:

Only driveItems with the file property can be downloaded.

So we need to make sure the target item has the propertiy file in the response when we called https://graph.microsoft.com/v1.0/me/drive/items/item_id

enter image description here

Then we need to pay attention to this section, when we can call the download api successfully, it will return a 302 redirection

enter image description here

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29
0

Not sure if this is your situation, but make sure you have checked-in your file if you happened to have uploaded it programmatically. OneDrive/SharePoint likes to put files into no-man's land if it has not been properly checked-in.

Documentation:

Download: https://learn.microsoft.com/en-us/graph/api/driveitem-checkout?view=graph-rest-1.0&tabs=http

Checkin: https://learn.microsoft.com/en-us/graph/api/driveitem-checkin?view=graph-rest-1.0&tabs=http

Nelson Nyland
  • 444
  • 5
  • 11