J Benjamin
J Benjamin

Reputation: 4782

Azure API Management: Replace querystring parameter name

New to APIM. Trying to change the exposed querystring parameter name (not the value) with a different name that the backend api expects

For example, APIM endpoint expects /v1/Customer?CustomerId=123

I think I need to use rewrite-url policy on the inbound section?

To change it to this: /v1/Customer?ExternalCustomerId=123


Was trying this, doesn't work

<set-query-parameter name="ExternalCustomerId" exists-action="append">
        <value>@(Context.Request.QueryString["CustomerId"])</value>
    </set-query-parameter>

Error: The name 'Context' does not exist in the current context

Upvotes: 1

Views: 9449

Answers (2)

jrm346
jrm346

Reputation: 81

This has changed as of september 2019. now use the following:

<set-query-parameter name="ExternalCustomerId" exists-action="append">
    <value>@(context.Request.Url.Query.GetValueOrDefault("CustomerId"))</value>
</set-query-parameter>

Upvotes: 6

Vitaliy Kurokhtin
Vitaliy Kurokhtin

Reputation: 7840

Try lower case "context". Plus QueryString is a IReadOnlyDictionary as described here: https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables, but there is a handy overload:

<set-query-parameter name="ExternalCustomerId" exists-action="append">
    <value>@(context.Request.QueryString.GetValueOrDefault("CustomerId"))</value>
</set-query-parameter>

Upvotes: 2

Related Questions