5

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.

Phillip Ngan
  • 15,482
  • 8
  • 63
  • 79

2 Answers2

10

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/.

Evandro de Paula
  • 2,532
  • 2
  • 18
  • 27
0

You only need to create "Query Parameters" in APIM instead of "Template parameters". Then your rewrite uri doesn't need to include the Query parameters as APIM will add it to backend url automatically once it is provided via inbound.

<rewrite-uri template="api/primes" />

if request URL is something like this:

https://example.com/sum?a=7&b=5

then the HTTP request sent to backend would be like this:

GET backendapi/api/primes?a=7&b=5

and if request URL is without query strings like this:

https://example.com/sum

then the HTTP request sent to backend would be simply like this:

GET backendapi/api/primes
Amir Chatrbahr
  • 2,260
  • 21
  • 31