Issue with deseralization in Microsoft Graph API batch request when receiving an HTML response with HTTP 503 status

Sébastien ANDRE 5 Reputation points
2025-10-01T12:47:50.3533333+00:00

Hello,

I'm encountering an issue with the Microsoft Graph API when performing batch requests.

In a specific case where one of the sub-requests fails with an HTTP 503 Service Unavailable, the body field of that sub-response contains raw HTML instead of a valid JSON error object. This breaks the expected Graph API contract and causes JSON deserialization to fail in our client.

Here is a trimmed-down example of the batch response I received (actual response included many sub-requests, most of which succeeded):

{"responses": [{"id":"80","status":204,"headers":{"Cache-Control":"private"},"body":null},{"id":"88","status":204,"headers":{"Cache-Control":"private"},"body":null},{"id":"89","status":204,"headers":{"Cache-Control":"private"},"body":null},{"id":"96","status":503,"headers":{"Content-Type":"text/html; charset=us-ascii"},"body":<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Service Unavailable</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Application Request Queue Full</h2>
<hr><p>HTTP Error 503. The application request queue is full.</p>
</BODY></HTML>
},{"id":"93","status":204,"headers":{"Cache-Control":"private"},"body":null},{"id":"92","status":204,"headers":{"Cache-Control":"private"},"body":null}]
}

The sub-response with ID 96 (status 503) includes an HTML string directly inside the "body" field.

This is not valid JSON, which violates the expected structure of a Graph API batch response.

The only workaround that i found is either to parse with regex and to try to repair the json itself (which is not really viable), or to retry the whole batch (which is not always doable in the case of a creation of contact or appointment)

I've seen this same problem posted here : https://learn.microsoft.com/en-us/answers/questions/5542571/batch-api-on-v1-0-batch-returns-invalid-json-when

and here : https://github.com/microsoftgraph/msgraph-sdk-serviceissues/issues/93

but the problem seems to be still present

Microsoft Security | Microsoft Graph

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.