How to specify rewrite url for query string parameters in Azure API Management

Phillip Ngan picture Phillip Ngan · Jul 9, 2018 · Viewed 8.1k times · Source

I'm using the Azure API Management to transform the incoming query string into another query string.

My transformation code is:

<policies>
    <inbound>
        <rewrite-uri template="api/primes?a={a}&b={b}" />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

When I try to save the edits, the error appears:

One or more fields contain incorrect values: 
'=' is an unexpected token. The expected token is ';'. Line 15, position 50.

which refers to the equals symbol as in a={a}. How do I correct the template of the rewrite-uri? The input url is for example https://example.com/sum?a=7&b=5.

Answer

Evandro Paula picture Evandro Paula · Jul 9, 2018

Try replacing:

<rewrite-uri template="api/primes?a={a}&b={b}" />

With:

<rewrite-uri template="api/primes?a={a}&amp;b={b}" />

Find more details at https://azure.microsoft.com/en-us/blog/policy-expressions-in-azure-api-management/.