Question

Difficulty: MediumDefine API Management Policies

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>

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

1
Identify the policy element that modifies query parameters in API Management.
The correct element is `<set-query-parameter>`.
This policy is specifically designed to add, replace, or delete query parameters.
2
Determine the correct value for the `exists-action` attribute to overwrite an existing query parameter.
The correct attribute value is `override`.
The `override` action ensures that if the query parameter is already present, its value will be replaced.

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.
Rate this question