Complete the Azure API Management (APIM) policy snippet to append or replace a query parameter in the backend request with the client's subscription ID.
Answer:You are configuring an inbound policy for an Azure API Management gateway. You need to ensure that a query parameter named `client-id` is sent to the backend service. If the `client-id` query parameter already exists in the incoming request, it must be overwritten with the subscription ID from the request context.
Complete the XML policy configuration by filling in the blanks.
xml
<inbound>
<base />
<【set-query-parameter】 name="client-id" exists-action="【override】">
<value>@(context.Subscription.Id)</value>
</【set-query-parameter】>
</inbound>
Complete the XML policy configuration by filling in the blanks.
xml
<inbound>
<base />
<【set-query-parameter】 name="client-id" exists-action="【override】">
<value>@(context.Subscription.Id)</value>
</【set-query-parameter】>
</inbound>
Answer
blank_1 = set-query-parameter, blank_2 = override
The `<set-query-parameter>` policy adds, replaces, or deletes query parameters in the request sent to the backend. Setting the `exists-action` attribute to `override` ensures that any existing query parameter with the same name is replaced by the subscription ID from the request context.
Step-by-Step Solution
Key Concept
API Management policies can manipulate incoming requests to backends. The `<set-query-parameter>` policy modifies request query strings, and setting `exists-action` to `override` replaces any pre-existing query parameter value.