I have stored a named value based on the user id, so I can identify the payload submitter, with a reference of my choosing.
When I use the policy below, I get the value as a string, rather than actually looking up the named value. If I simply write the user id inside the double curly brackets rather than getting it dynamically from the context, the lookup works fine and it substitues with the named value I want.
Is it not possible to do in a simple manner?
<policies>
<inbound>
<set-header name="x-request-context-data" exists-action="override">
<value>{{@(context.User.Id)}}</value>
</set-header>
</inbound>
</policies>
Output:
x-request-context-data: {{@(context.User.Id)}}
Answered at MSDN.
While you can use named values in policy expressions, the other way around is not supported and not possible to support as described in this feature request.
Workarounds would be to either
- Store named values as a JSON string or a CSV string with key=value pairs. Then use policy expressions to parse and fetch the required value.
- Use control flow policies for run time decisions.
- For complex cases, offload to a function app but use value caching policies for improved latency if possible
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With