0

I have URL in the below format, and I want to decode the query string and re-write the URL.

https://api.test.abc.com/parameters?username=%7Busername%7D

How can I decode username using policies and re-write it in the following format:

API Endpoint: /api/affiliated/users/userInfo/?username=abcd.gmail.com

Many thanks in advance.

Micheal J. Roberts
  • 3,735
  • 4
  • 37
  • 76

3 Answers3

1

You can use the System.Net.WebUtility with in the APIM policies

System.Net.WebUtility.UrlDecode(context.Request.Url.Query["username"]
Asthiss
  • 221
  • 2
  • 8
0

You can decode it manually.

context.Request.Url.Query["username"] | Replace:'%7B','{' | Replace:'%7D','}'

Save that username in one variable and use it in rewrite template.

I too want to know some method to decode url in APIM policy.

Chilarai
  • 1,842
  • 2
  • 15
  • 33
vinod rawool
  • 23
  • 1
  • 4
0

We cannot directly decode, as there is no option, we have to do delete the first query parameter and rewrite the URI by changing and decoding the query parameter. I used the below code snippet to execute that. (as the question was also to replace the userName in the URL with visibleToUserId along with decoding the value.)

@((Convert.ToBase64String(Encoding.UTF8.GetBytes((string)context.Request.MatchedParameters[\"visibleToUserId\"]))).Replace('=', '~').Replace('+', '-').Replace('/', '_'))