Radu Olteanu
Radu Olteanu

Reputation: 443

Azure API Management access specific values from a defined variable

I'm using the Azure API management, and I have the following response stored in this variable

<set-variable name="externalAPIResponse" value="@((IResponse)context.Variables["response"])" />

The response, has the following structure :

 "value": {
    "status": {
        "code": 400,
        "reason": "Bad Request"
    },
...
}

I'm struggling to access the status code from this variable, in order to take further decisions based on the value.

Upvotes: 0

Views: 928

Answers (1)

Mandar Dharmadhikari
Mandar Dharmadhikari

Reputation: 1119

@{
  var response = JObject.Parse((IResponse)context.Variables["response"]);
  string code = response?['value']?['status']?['code'];

  return code;


}

Upvotes: 1

Related Questions