No way to provide base64 encoded MIME content when replying to message.
Describe the bug This documentation says there are 2 ways to create a draft reply for an existing outlook message. First way is probably working, but in v5 there is no way to create this Http Post request for sending raw MIME content.
Microsoft.Graph.Me.Messages.Item.CreateReply.CreateReplyPostRequestBody this metadata does not include a property (Content) to provide raw mime.
Expected behavior There should be a method or metadata update that will enable developers to provide encoded mime content to create reply for a message as a draft.
Additional context Version 5.4.0
Thanks for raising this @bkaankose
The metadata used to generate the SDK is missing the Mime path but this can be possibly resolved as below as this is fixed.
var base64content = "";
var requestInformation = graphClient.Me.Messages["{message-id}"].CreateReply.ToPostRequestInformation(new ());
requestInformation.Headers.Clear();// replace the json content header
requestInformation.SetStreamContent(new MemoryStream(Encoding.UTF8.GetBytes(base64content)));
var result = await graphClient.RequestAdapter.SendAsync<Message>(requestInformation, Message.CreateFromDiscriminatorValue);
Thanks for the alternative, it works for SendAsync if I add "text/plain" as it is suggested in the documentation, but it doesn't work for Batch requests. I construct the RequestInformation and pass it to Batch with AddBatchRequestStepAsync.
Calling this line graphClient.Batch.PostAsync(batchContent)
fails with the following exception:
JsonReaderException: 'R' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
StackTrace
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter)
at System.Text.Json.JsonDocument.<ParseAsyncCore>d__68.MoveNext()
at Microsoft.Graph.BatchRequestContent.<GetRequestContentAsync>d__18.MoveNext()
Even though the response is expected to return Message, I believe response parser is trying to deserialize the response as 'text/plain' as it was stated in my request.
Is there a way to parse the response without having crash on PostAsync call?
To add to the context, response returned from this call is actually bas64 encoded string of the mime content.
This issue also applies to both Microsoft.Graph.Me.SendMailRequestBuilder.PostAsync() and Microsoft.Graph.Users.Item.SendMail.SendMailRequestBuilder.PostAsync() as well.
Thanks for raising this @bkaankose
The metadata used to generate the SDK is missing the Mime path but this can be possibly resolved as below as this is fixed.
var base64content = ""; var requestInformation = graphClient.Me.Messages["{message-id}"].CreateReply.ToPostRequestInformation(new ()); requestInformation.Headers.Clear();// replace the json content header requestInformation.SetStreamContent(new MemoryStream(Encoding.UTF8.GetBytes(base64content))); var result = await graphClient.RequestAdapter.SendAsync<Message>(requestInformation, Message.CreateFromDiscriminatorValue);
This was working for 5.4.0 but looks like it is broken now. I receive 415 from the API in 5.26.0.
@andrueastman do we have some progress on this P1 issue?
I believe 415 suggests that the content type is incorrect. Any chance it works out if you update the sample as below to include the content type header when setting the content @bkaankose.
requestInformation.SetStreamContent(new MemoryStream(Encoding.UTF8.GetBytes(base64content)),"text/plain");
Thanks for the alternative, it works for SendAsync if I add "text/plain" as it is suggested in the documentation, but it doesn't work for Batch requests. I construct the RequestInformation and pass it to Batch with AddBatchRequestStepAsync.
Calling this line graphClient.Batch.PostAsync(batchContent)
fails with the following exception:
JsonReaderException: 'R' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
StackTrace
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack) at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter) at System.Text.Json.JsonDocument.<ParseAsyncCore>d__68.MoveNext() at Microsoft.Graph.BatchRequestContent.<GetRequestContentAsync>d__18.MoveNext()Even though the response is expected to return Message, I believe response parser is trying to deserialize the response as 'text/plain' as it was stated in my request.
Is there a way to parse the response without having crash on PostAsync call?
This should already be resolved in the latest SDK version as you set non json bodies in Batch requests via https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/pull/701
As the batch request issue is resolved, we would need to resolve the metadata issue to include the text/plain format of the message.