Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to provide base64 encoded MIME content when replying to message. #1802

Open
bkaankose opened this issue Apr 2, 2023 · 7 comments
Open

Comments

@bkaankose
Copy link

bkaankose commented Apr 2, 2023

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

@ghost ghost added the Needs: Triage label Apr 2, 2023
@ghost ghost added this to Issues to triage in Graph SDK - DotNet Apr 2, 2023
@andrueastman
Copy link
Member

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);

@bkaankose
Copy link
Author

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?

@bkaankose
Copy link
Author

To add to the context, response returned from this call is actually bas64 encoded string of the mime content.

@asbjornheid
Copy link

This issue also applies to both Microsoft.Graph.Me.SendMailRequestBuilder.PostAsync() and Microsoft.Graph.Users.Item.SendMail.SendMailRequestBuilder.PostAsync() as well.

@bkaankose
Copy link
Author

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.

@bkaankose
Copy link
Author

@andrueastman do we have some progress on this P1 issue?

@andrueastman
Copy link
Member

andrueastman commented Dec 5, 2023

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 microsoftgraph/msgraph-sdk-dotnet-core#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Graph SDK - DotNet
  
Issues to triage
Development

No branches or pull requests

3 participants