POST API Call works in test but not from Postman - get 500 HTTP response code

Robert Heynen 50 Reputation points

I have set up an API management POST api operation that reads the incoming body and creates variables from the values in the policy, passing it on as query variables to the backend API call and returning the result. Sample:

 <set-variable name="TaskName" value="@{if (context.Request.Body != null){ return (string)context.Request.Body.As<JObject>(preserveContent: true).SelectToken("TaskName");} else {return "";}}" />      

This works when I send a body in the Azure the APIM Test area that looks like this:

        <set-query-parameter name="TaskName" exists-action="append">

However, it DOES NOT work when submitting a request in POSTMAN - it renders a 500 status code. For the record, I created a GET api operation in the same APIM API that accepts Query Variables and passes them on as query variables to the backend API call. This works both in test and in POSTMAN. Lastly, if I establish a Representation inside AZURE APIM on the POST api call, it no longer works in the APIM Test area. The external API being called is a webAPI hosted by my company on a different server.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,792 questions
{count} votes