2
votes

Using the send-request Policy in Azure APIM. Able to get the response and extract the Body. However, struggling with extracting the response.status.code

The value of this @(context.Response.StatusCode) is 200 if the request is sent, i am trying to capture this value...

send-request (88 ms)
{
    "response": {
        "status": {
            "code": 200,
            "reason": "OK"
        }
    }
}
1

1 Answers

4
votes
Hope below solution will work for you.

<choose>
 <when condition="@(((IResponse)context.Variables["response-variable-name"]).StatusCode == 200)">
       <set-variable name="xxx" value="@(((IResponse)context.Variables["response-variable-name"]).Body.As<JObject>(preserveContent: true).ToString())" />
</when>
<otherwise>
    <return-response>
      <set-status code="404" reason="Not Found" />
      <set-body>@(((IResponse)context.Variables["response"]).Body.As<JObject>(preserveContent: true).ToString())</set-body>
    </return-response>
 </otherwise>
</choose>