Search code examples
azureasp.net-coreazure-devopsazure-api-managementazure-api-apps

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.


Solution

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