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
I am correctly logged using oauth2, all other methods work such as '/me', '/me/drive/recent', '/me/drive/sharedWithMe'
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?
Firstly, we need to notice that in the api document, it mentioned:
So we need to make sure the target item has the propertiy
file
in the response when we calledhttps://graph.microsoft.com/v1.0/me/drive/items/item_id
Then we need to pay attention to this section, when we can call the download api successfully, it will return a 302 redirection