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

Messages.Item.SendRequestBuilder.ToPostRequestInformation() does not work in batch. #2628

Open
bkaankose opened this issue Aug 19, 2024 · 2 comments
Labels
area:documentation Focused on documentation of the product Status: Needs investigation type:bug A broken experience

Comments

@bkaankose
Copy link

bkaankose commented Aug 19, 2024

Describe the bug

Including following post request information into batch

var sendDraftRequest = _graphClient.Me.Messages[messageId].Send.ToPostRequestInformation();

returns the following error inside batch:

{"error":{"code":"BadRequest","message":"Write request id : f4f09b02-155a-47e7-86da-a89930ad6590 does not contain Content-Type header or body.","innerError":{"date":"2024-08-19T01:08:18","request-id":"7d3af893-af46-4dc4-9dbb-c4edd72dcd92","client-request-id":"31088810-bb70-466a-895c-925e315ef7a8"}}}

This documentation states that body is not required.

I extracted this error from the BatchResponseContentCollection itself in the debugger, because none of the APIs provided returns a response for the actual request.

BatchResponseContentCollection.GetResponseByIdAsync does not return any responses for the error even though the collection itself have the proper ids:

1. Confirming requestId
image

2.1. Confirming that response exists
image

2.2 Confirming that key that associated with the response exists
image

3. Confirming that response is not returned by proper id
image

Expected behavior

If no error, POST request is executed inside batch.
If error, return the request error with BatchResponseContentCollection.GetResponseByIdAsync

How to reproduce

Just include _graphClient.Me.Messages[messageId].Send.ToPostRequestInformation() request information inside a batch using AddBatchRequestStepAsync

SDK Version

5.56.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

@bkaankose bkaankose added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 19, 2024
@bkaankose
Copy link
Author

Workaround

var sendDraftRequest = _graphClient.Me.Messages[mailCopyId].Send.ToPostRequestInformation((config) =>
{
    config.Headers.Add("Content-Type", "application/json");
});

sendDraftRequest.Headers.Clear();
sendDraftRequest.Headers.Add("Content-Type", "application/json");
sendDraftRequest.Content = new MemoryStream(Encoding.UTF8.GetBytes("{}"));
sendDraftRequest.HttpMethod = Method.POST;

I read in SO that Post requests in batch handled differently. Is this documented somewhere? Will it be fixed? I saw with Kiota version you had some fixes but seems like it doesn't work for all requests.

@shemogumbe shemogumbe added area:documentation Focused on documentation of the product and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Aug 19, 2024
@andrueastman
Copy link
Member

Thanks for raising this @bkaankose

For context, the batching endpoint unwraps the json object created and makes the individual requests on your behalf by deserializing the json object into a request. https://learn.microsoft.com/en-us/graph/json-batching

As you highlighted, the docs at https://learn.microsoft.com/en-us/graph/api/message-send?view=graph-rest-1.0&tabs=http show that a request bod is not needed. This is the same for the metadata as the generated ToPostRequestInformation does not have parameter for the requestBody(if it did we could pass an empty object and this would generate the same json as the workaround).

This suggests that the batch endpoint needs an empty body property in the Json in the event that a request is POST which shouldn't ideally be the case.
This will need to be investigated before any changes are made as this may be fix needed on the API side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:documentation Focused on documentation of the product Status: Needs investigation type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

3 participants