Describe the bug
I'm attempting to create a file upload session with pre-set FileSystemInfo using CreateUploadSessionRequestBuilder.
The request builder serializes the CreateUploadSessionPostRequestBody object into the following JSON:
{
"item": {
"fileSystemInfo": {
"createdDateTime": "2000-01-01T00:00:00-06:00",
"lastModifiedDateTime":"2000-01-01T00:00:00-06:00"
},
"@microsoft.graph.conflictBehavior":"replace"
}
}
Which results in a 400 error when attempting to POST
Expected behavior
Serialize the request body so that the "fileSystemInfo" property appears after the "@microsoft.graph.conflictBehavior" directive (which is what the graph API wants?!?) and the POST succeeds:
How to reproduce
DateTime created = new DateTime(2000, 1, 1);
var uploadSessionRequestBody = new Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionPostRequestBody
{
Item = new DriveItemUploadableProperties
{
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "replace" },
},
FileSystemInfo = new Microsoft.Graph.Models.FileSystemInfo
{
CreatedDateTime = created,
LastModifiedDateTime = created
}
}
};
var uploadSession = await graphClient.Drives[driveId]
.Root
.ItemWithPath(targetPath)
.CreateUploadSession
.PostAsync(uploadSessionRequestBody);
SDK Version
5.103.0
Latest version known to work for scenario above?
No response
Known Workarounds
Use "ToPostRequestInformation" to create a request object and manipulate the request body before sending:
var uploadSessionRequestBody = new Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionPostRequestBody
{
Item = new DriveItemUploadableProperties
{
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "replace" },
},
FileSystemInfo = new Microsoft.Graph.Models.FileSystemInfo
{
CreatedDateTime = created,
LastModifiedDateTime = created
}
}
};
var uploadSessionRequest = Graph.Drives[driveId]
.Root
.ItemWithPath(targetPath)
.CreateUploadSession
.ToPostRequestInformation(uploadSessionRequestBody);
using (var reader = new StreamReader(uploadSessionRequest.Content))
{
var jsonString = await reader.ReadToEndAsync();
JsonNode? rootNode = JsonNode.Parse(jsonString);
if (rootNode != null && rootNode["item"] is JsonObject itemObj)
{
JsonNode? fileSystemInfoNode = itemObj["fileSystemInfo"];
JsonNode? conflictBehaviorNode = itemObj["@microsoft.graph.conflictBehavior"];
if (fileSystemInfoNode != null && conflictBehaviorNode != null)
{
itemObj.Remove("fileSystemInfo");
itemObj.Remove("@microsoft.graph.conflictBehavior");
itemObj.Add("@microsoft.graph.conflictBehavior", conflictBehaviorNode);
itemObj.Add("fileSystemInfo", fileSystemInfoNode);
}
uploadSessionRequest.Content = new StringContent(rootNode.ToJsonString()).ReadAsStream();
}
}
var uploadSession = await Graph.RequestAdapter.SendAsync(
uploadSessionRequest,
UploadSession.CreateFromDiscriminatorValue,
new Dictionary<string, ParsableFactory<IParsable>>{{ "XXX", ODataError.CreateFromDiscriminatorValue }});
Debug output
No response
Configuration
No response
Other information
I'm not sure if this is an issue with the SDK because typically an API shouldn't care about the order in which JSON fields appear. I've seen examples of .net SDK code with upload sessions that include file system info so I'm not sure at which point this broke.
Describe the bug
I'm attempting to create a file upload session with pre-set FileSystemInfo using CreateUploadSessionRequestBuilder.
The request builder serializes the CreateUploadSessionPostRequestBody object into the following JSON:
Which results in a 400 error when attempting to POST
Expected behavior
Serialize the request body so that the "fileSystemInfo" property appears after the "@microsoft.graph.conflictBehavior" directive (which is what the graph API wants?!?) and the POST succeeds:
How to reproduce
SDK Version
5.103.0
Latest version known to work for scenario above?
No response
Known Workarounds
Use "ToPostRequestInformation" to create a request object and manipulate the request body before sending:
Debug output
No response
Configuration
No response
Other information
I'm not sure if this is an issue with the SDK because typically an API shouldn't care about the order in which JSON fields appear. I've seen examples of .net SDK code with upload sessions that include file system info so I'm not sure at which point this broke.