0

I have an API in APIM. When my API is called, I want to remove one of the query parameters from the URL ("ax-ky" in the code) and keep the rest (Page). I was thinking policies in APIM would help me remove "ax-ky". I've tried the solutions here and here but they have not been working with my API. After implementing the new inbound policy below, I get 500 status code with the message "Internal server error".

Currently my code is in the "Inbound" policy, shown below:

        <set-query-parameter name="ax-ky" exists-action="override">
            <value>@(context.Product.Name)</value>
        </set-query-parameter>
        <rewrite-uri template="_/_?Page={Page}" />

Edit: Adding screenshot of Trace "set-query-parameter" --> Query parameter is removed in set-query-parameter but not when the URL is returned to the user. enter image description here

bowlingh23
  • 49
  • 7

1 Answers1

0

I have tried to reproduce the issue at my environment and got the expected result

Here I am using Echo API wherein I am removing param1 from Get resource operation and keeping the rest URL as it is by using the below policy

<inbound>
<base />
<set-query-parameter  name="param1"  exists-action="delete"  />
</inbound> 

Test Result

enter image description here

Requested URL is

enter image description here

Response

enter image description here

In Trace, I could see below changes in the Request URL

enter image description here

Try changing exists-action="override" to exists-action="delete" in your policy, you will get the result too.

Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6
  • Hi @Ikhtesam Afrin, I did exactly what you did and it still does not change the URL in my case. In this situation "ax-ky" is the variable that is the subscription key the user passes, could that be the reason why it is not deleting? – bowlingh23 Jun 26 '23 at 12:53
  • Can you share the trace screenshot please like the way I have shared for set query parameter? – Ikhtesam Afrin Jun 26 '23 at 13:55
  • I added a screenshot to my initial post. The query parameters are removed in set-query-parameters but not when I access the API through my browser. The parameter is still visible in the URL. – bowlingh23 Jun 26 '23 at 14:15
  • set-query-parameters removes the query parameter from the request URL and send the modified URL to backend. You can see the detailed information in Trace. – Ikhtesam Afrin Jun 26 '23 at 17:02
  • Gotcha, it makes sense. Is there a way to make this backend URL the current URL that the browser shows? – bowlingh23 Jun 26 '23 at 17:10
  • Not sure if this is even feasible to achieve as we are sending the current modified URL to backend only. I am aware of set-backend-service policy but it sets the backend url and even rewrite-url change the current url and send it to backend. – Ikhtesam Afrin Jun 26 '23 at 17:39
  • I appreciate your help, thank you. I'll still be looking into if it is possible. – bowlingh23 Jun 26 '23 at 19:33