I am using this code for azure APIM policies
<set-variable name="newRequest" value="@(context.Request.Body?.As<JObject>(preserveContent: true))" />
<set-variable name="insured-id" value="@(context.Request.MatchedParameters["id"].Last())" />
<send-request mode="new" timeout="20" response-variable-name="id" ignore-error="false">
<set-url>@($"https://api.dev.com/external/workRequest/get")</set-url>
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-header name="Authorization" exists-action="override">
<value>@(context.Request.Headers.GetValueOrDefault("Authorization","scheme param"))</value>
</set-header>
<set-body>{"insuredId": @($"{(string)context.Variables["insured-id"]}")}</set-body>
</send-request>
<choose>
<when condition="@((int)((IResponse)context.Variables["id"]).Body.As<JObject>(preserveContent: true)["workRequests"]["entityStatus"]== 1)">
<return-response response-variable-name="id">
<set-status code="400" reason="VOID" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value></set-header>
<set-body>{"statusCode": 400,
"message": "The insured cannot be voided as it is currently attached with one or more active workrequest"}</set-body>
</return-response>
</when>
<otherwise />
</choose>
I am taking an insuredId from template parameter of the API operation where I am implementing the APIM policies & using it in the set-body, this will list all the workrequests for that insuredId.
The payload for the POST is something like
{"insuredId": template-parameter}
When returning a response getting 500 error. How to resolve this. The condition which is there is okay. I am suspecting error in set body.
Also how to check whether a particular string like "entityStatus": 1 is there in the response of api, because this https://api.dev.com/external/workRequest/get url will give a list of workrequest records in array form
The request to
https://api.dev.com/external/workRequest/getis failing:The response of failed request is stored in the variable
id. But this response not return any json document in the body.Therefore, the following expression is failing and an error 500 is returned:
"(int)((IResponse)context.Variables[\"id\"]).Body.As<JObject>(preserveContent: true)[\"workRequests\"][\"entityStatus\"]== 1",Please check the supported http-methods of
https://api.dev.com/external/workRequest/get.Maybe your code has to changed to
GET:Trace of request:

UPDATE for question from comments:
It's better to create a new Stackoverflow Question instead of doing it in comments. Maybe that's what you asking for:
Request body:
Response:
A variable is assigned with a
truevalue of anyentityStatusequals1.The
choosepolicy returns a 400 withentityStatusequalstrue.Policy: