I have an API hosted on Azure and I have started using the Azure API Management. One of my API endpoint is a GET and it requires a body in the form of JSON to be passed to the endpoint. On my postman, I am able to hit the actual API (hosted on Azure) and send the body and I am able to get some results. But when i tried to hit the api on azure api management, I am getting the following exception, although i am sending the request body:
{
"errors": {
"": [
"A non-empty request body is required."
]
},
"type": "https://tools.ietf.org/html/rfcXXXX#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "XXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
Am I missing some configuration on the Azure Api management? I did look up the set policies and i used the following on my inbound but this is still not working
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body template="liquid">{{body.json}}"}</set-body>
Any insight on how i can fix this issue will be greatly appreciated. Thanks in advance.
I can use the following policy to set the GET request body.
<inbound>
<base />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body template="liquid">{"QueryString": "123", "param1": "456"}</set-body>
<set-body>@{
JObject inBody = context.Request.Body.As<JObject>();
return inBody.ToString();
}</set-body>
</inbound>
When I test it, I can see that it has been added into body successfully. And I can also get it by using context.Request.Body.As<JObject>()
.
I noticed that your body is {{body.json}}"}
, which seems to be incorrect in format. You should use {{body.json}}
and make sure that body.json
contains the exact content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With