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?