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
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