How to create and use list in Azure API-manager policy?

Viewed 32

Background: I am defining an API in Azure API Management. I have defined a policy on "All operations" level. This policy does a couple of things. One of the things it does is setting a variable in the context object, so I can re-use the variable in when condition.

What I need help with:

How can I define a list in Azure API-M policy, which I can refer to in when condition?

Code example:

All operations policy:

<policies>
    <inbound>
        <base />
        <set-variable name="someList" value="[a,b,c,d]" />
        <when condition="@(context.Variables["someList"].Contains("a"))"
        </when>
        <otherwise>
        </otherwise>
    </inbound>
</policies>

It seems that my issue is that the variable "someList" is not recognized as an array, but as a String = "[a,b,c,d]". So basically, it will return true if the condition would say Contains("[").

I have also tried to store value as named values, but named values can't contain a Array as value.

What I want to achieve is keeping a list of subscriptions, so that I can match incoming subscription key in request to a list of pre-defined subscription keys.

0 Answers
Related