Reputation: 4824
I have a simple test in an Azure API Manager Outgoing Policy
<policies>
<inbound>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<set-body template="liquid">
{% if context.Request.OriginalUrl.Query.param1 == 'test' %}
Matched
{% else %}
Not Matched
{% endif %}
Hello : {{context.Request.OriginalUrl.Query.param1}}
</set-body>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
And I post
/echo/resource?param1=test
I get
Not Matched
Hello : test
I can't figure out the syntax to check the value for param1 and act accordingly in the body. I've not found any decent documentation on this which helps. I've tried this as well as
{% if context.Request.OriginalUrl.Query.param1.Equals('test') %}
Can somebody advise on the syntax I need to check this? This should be trivial and it's driving me nuts! :)
Thanks
Upvotes: 1
Views: 1207
Reputation: 4824
In addition to Markus's answer you can also do it like this
{% if context.Request.OriginalUrl.Query.param1[0] == 'test' %}
It makes sense that it's an array of values and that's why the comparison was failing.
Upvotes: 2
Reputation: 3937
It works for me if I use a variable:
<policies>
<inbound>
<set-variable name="param" value="@(context.Request.Url.Query.GetValueOrDefault("param1"))" />
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<set-body template="liquid">
{% if context.Variables["param"] == 'test' %}
Matched
{% else %}
Not Matched
{% endif %}
Hello : {{context.Request.OriginalUrl.Query.param1}}
</set-body>
<base />
</outbound>
<on-error>
<base />
</on-error>
Result:
Matched
Hello: test
Upvotes: 2