Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure API Management Policy - Dynamic named value select

Tags:

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)}}
like image 566
madsnb Avatar asked Oct 25 '19 07:10

madsnb


1 Answers

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
like image 77
madsnb Avatar answered Sep 19 '22 22:09

madsnb