I'm trying to do the following:
I have an API in APIM that receives an certain header with a key that is set in a APIM named value. For example:
http://apimSomeUrl.com/apiName/whatever request header: "country" with the value "bolivia"
through a APIM policy I want to get the value of the Named Value "bolivia" and then set as the new uri.
for example. I have a named value live "bolivia": http://google.com
When the APIM receives the request it get the header value and set it in a context variable
<set-variable name="newUrl" value="
@{
string [] HostNameHeader;
context.Request.Headers.TryGetValue("tenant", out HostNameHeader);
return HostNameHeader[0];
}
" />
Then I want to get the "newUrl" value and get the named value Bolivia, setting the request Uri with its value
I've tried this:
<set-variable name="tenant" value="
@{
string [] HostNameHeader;
context.Request.Headers.TryGetValue("tenant", out HostNameHeader);
return HostNameHeader[0];
}
" />
<set-header name="CustomHeader" exists-action="override">
<value>{{@((string)context.Variables["tenant"])}}</value>
</set-header>
<!--<set-backend-service base-url="baseURLfromNamedValueComesHere" />-->
But the policy doesn't replace this {{@((string)context.Variables["tenant"])}}
it keeps writing as string enter image description here