Policy rewrite-uri To Append Context Variable in Azure APIM

In my case, my URL was

https://test.com/send/

I need to add query string from context variable name (name = myName)

https://test.com/send/myName

This is working for me:

<rewrite-uri template="@($"{(string)context.Variables["name"]}")" />

I ended up using this call as shown as an alternative:

<rewrite-uri template="@($"/account/{(string)context.Variables["accountKey"]}/")" />


Configure the inbound rule in the policy as follows:

<inbound>
    <base />
    <set-variable name="accountKey" value="232" />
    <rewrite-uri template="@{
        return "/account/" + context.Variables.GetValueOrDefault<string>("accountKey");
    }"/>
</inbound>

{} in rewrite-uri are for query string parameters in the original request URL.

Find more details about rewrite-uri section in the Microsoft docs at Rewrite URL - API Management transformation policies.