Messages.Item.SendRequestBuilder.ToPostRequestInformation() does not work in batch.
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
2.1. Confirming that response exists
2.2 Confirming that key that associated with the response exists
3. Confirming that response is not returned by proper id
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
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.
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.
I have the same issue for batched requests to the below endpoint. @andrueastman is the workaround posted above the suggested approach?
POST https://graph.microsoft.com/v1.0/identityGovernance/entitlementManagement/assignmentRequests/{assignmentRequestId}/cancel