Azure APIM - Body of the request does not conform to the definition which is associated with the content type application/json. Invalid type. Expected Object but got String

2023-05-18T15:01:17.87+00:00

We have noticed a new issue in our Azure API Management's "TEST" tab, this is a tab under an API which we use to test the API sometime. The issue says : -**
{"source": "validate-content","timestamp": "2023-05-18T03:17:08.4977100Z","elapsed": "00:00:02.2121646","data": {"name": "application/json","type": "RequestBody","validationRule": "IncorrectMessage","details": "Body of the request does not conform to the definition which is associated with the content type application/json. Invalid type. Expected Object but got String. Line: 1, Position: 114","action": "Detected"}}**

As you will notice, this a validate content step in our policy. When we submit the request from Postman or another tool, we do not see this error.

So we added some more trace to see what's going on. And below is a trace which prints the request body: -

**
{"source": "trace","timestamp": "2023-05-18T03:17:08.5289627Z","elapsed": "00:00:02.2524943","data": {"message": "Expression was successfully evaluated.","expression": "\n return context.Request.Body.As<string>(preserveContent: true);\n ","value": ""{\"userid\":\"1213\",\"environment\":\"stri213213ng\",\"quoteNumber\":\"123123\",\"policyNumber\":\"123123213\"}""}}**

And below is trace when we submitted the same request from Postman: -

{"source": "trace","timestamp": "2023-05-18T03:23:15.7330257Z","elapsed": "00:00:00.0120812","data": {"message": "Expression was successfully evaluated.","expression": "\n return context.Request.Body.As<string>(preserveContent: true);\n ","value": "{"userid":"1213","environment":"stri213213ng","quoteNumber":"123123","policyNumber":"123123213"}"}}

We see that the request body is escape very differently when using "test" tab in azure api management and it seems due to this it fails in JSON parsing. We do also have "Content-Type" header set to "application/json" but still same result.

Any ideas on what we could be missing? We also noticed that this was working before 16th May 2023 and it seems it either some windows or microsoft update could be causing this?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,464 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,480 questions
0 comments No comments
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2023-05-18T16:00:17.41+00:00

    Chaudhary Bhaskar - Cincinnati-AMIG Thanks for posting your question in Microsoft Q&A. We found that after upgrade, API calls were failing to read the request body as JObject due to a bug. Our engineering team has identified the impacted services and rolled them back for immediate mitigation.

    Sorry for the inconvenience caused by the issue. If you still face the issue, please let us know or feel free to open a support ticket for immediate mitigation.


0 additional answers

Sort by: Most helpful

Your answer

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