When requesting a Resumeable Upload session per the documentation here, I am expecting to get a 200 ok, with a URL to upload the file content to.
URL
Per the documentation I should be able to use the following URL format:
{{BaseURL}}/drives/{{DriveId}}/items/{{FolderId}}/createUploadSession
Body
The request body should be JSON content like this:
{
"item": {
"@microsoft.graph.conflictBehavior": "replace",
"description": "description",
"fileSize": 1234,
"fileSystemInfo": {
"createdDateTime": "2020-07-22T23:10:31",
"lastAccessDateTime": "2020-07-22T23:10:31",
"lastModifiedDateTime": "2020-07-22T23:10:31"
},
"name": "filename.txt"
},
"deferCommit": true
}
In HTTP a complete request should look like this
POST /drives/b!Gsfre...asdOe/items/01SSGR...64FSSC/createUploadSession HTTP/1.1
Host: https://graph.microsoft.com/v1.0
Authorization: Bearer eyJ0e...TOKEN...S5lEw
Content-Type: application/json
{
"item": {
"@microsoft.graph.conflictBehavior": "replace",
"description": "description",
"fileSize": 1234,
"fileSystemInfo": {
"createdDateTime": "2020-07-22T23:10:31",
"lastAccessDateTime": "2020-07-22T23:10:31",
"lastModifiedDateTime": "2020-07-22T23:10:31"
},
"name": "filename.txt"
},
"deferCommit": true
}
What you end up with is a 400 Bad Request
{
"error": {
"code": "invalidRequest",
"message": "Invalid request",
"innerError": {
"date": "2020-07-23T00:33:44",
"request-id": "d913b71b-4e21-496a-8276-545625d1b4f3"
}
}
}
There are ways of Getting a valid request, however they do not follow the documentation
URL
The URL can be fixed by adding a file name to it and some colons
/drives/{{DriveId}}/items/{{FolderId}}:/{{FileName}}:/createUploadSession
None of the URL formats shown in the documentation include a file name.
This may be a documentation problem or at least could be fixed by a simple change to the documentation since it doesn't really change the functionality of the API.
Body
The Body however is a different problem. As far as I can tell the only parameters "item" accepts are "@microsoft.graph.conflictBehavior" and "name". When I add any other parameters I get the 400 bad request error
Even following the exact example in the documentation results in an error
{
"item": {
"@microsoft.graph.conflictBehavior": "rename",
"description": "description",
"fileSize": 1234,
"name": "filename.txt"
}
}
The documentation says the "item" parameter can take 'driveItemUploadableProperties' which consist of "description", "fileSize", "fileSystemInfo", and "name". Adding any parameters other than "name" results in an error.
POST /drives/b!GZz...DriveId...nsBOe/items/01S...FolderId...76C:/filename.txt:/createUploadSession
Host: https://graph.microsoft.com/v1.0
Authorization: Bearer eyJ0e...TOKEN...S5lEw
Content-Type: application/json
{
"item": {
"@microsoft.graph.conflictBehavior": "rename",
"description": "description",
"fileSize": 1234,
"name": "filename.txt"
}
}
400 Bad Request
{
"error": {
"code": "invalidRequest",
"message": "Invalid request",
"innerError": {
"date": "2020-07-23T00:47:40",
"request-id": "dc57eaa5-9e05-4f4e-a56f-3c0945de9287"
}
}
}
Thank you,
Ryan
Thank you for your contribution to OneDrive API Docs. We will be triaging your incoming issue as soon as possible.
Thanks for your feedback. We'll be tagging to put this on our documentation backlog - if you have other more pressing issues, please create a new issue for us to bring to our attention.
@chackman @JeremyKelley Any progress on this? This documentation issue was really annoying for me just now and will probably waste the time of other developers in the future too. Also I would much prefer to use the API according to the documentation too make sure that it wont make break any applications when this is will be adressed.
It's still on our backlog. Anyone is welcome to contribute a PR to improve our documentation, please do so if you would like to.
@chackman please note that there are actual implementation bugs described in this issue. I don't think that this can/should be solved by the community since the first step is to fix any bugs with the driveItemUploadableProperties. After that the most appropriate solution would probably be to keep everything compatible with the current behavior, put a big warning in the documentation (that the current api has some weird quirks) and plan on doing it better in v2...
We have those on our backlog.
Unfortunately, with respect to the parameters, the documentation does not call out that (currently) description, fileSize, and lastAccessDateTime are not supported values to pass into the createUploadSession API in OneDrive for Business / SharePoint.
@chackman please also note the bug with the url and the filename being provided twice (in the url and driveItemUploadableProperties)
For anyone arriving to this now, the issue seems to be a service bug whereby the ordering of the keys in the JSON is important. This should be annotated in the docs.
https://github.com/microsoftgraph/msgraph-sdk-serviceissues/issues/17#issuecomment-461227699
Put fileSystemInfo first in your dictionary - it works
For anyone else struggling with this, the following incantation worked for my small business Microsoft 365 account:
URL
/drives/{driveId}/items/{itemId}:/{fileName}:/createUploadSession
BODY
{
"item": {
"@microsoft.graph.conflictBehavior": "rename"
},
"deferCommit": true
}