can we create a common policy for global and product scope?

akhilas@secful.com 20 Reputation points
2024-04-22T08:59:31.0866667+00:00

I created an API Management (APIM) policy at the product level and now we need to set up a policy that can be used at the global, product, and API scopes. I initially created a product-level policy and tried to place it at the global scope, but it resulted in an error. Is it possible to create a single policy that works across all scopes?When I use the policy at All API level, I basically:

  • replace the original policy.xml from

<backend>
<base />
</backend>
to
<backend>
<forward-request />
</backend>

  • and remove all lines that have

<base/> (there should be three of them).then it work for global . is any other option?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,768 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 21,321 Reputation points
    2024-04-23T05:27:38.16+00:00

    @akhilas@secful.com Thanks for reaching out. From the description i understand that you have created a product-level policy and tried to place it at the global scope, but it resulted in an error. you want to know if there is any other option to create a policy that can be used at the global, product, and API scopes.

    if you want to use a policy at the global, product, and API scopes, you can define the policy at the global scope and use the base element to inherit the policy at the product and API scopes. For example, you can define a policy at the global scope as follows:

    <policies> 
    <inbound> <!-- statements to be applied to the request go here --> 
    </inbound> 
    <backend> <!-- statements to be applied before the request is forwarded to the backend service go here --> 
    </backend> 
    <outbound> <!-- statements to be applied to the response go here --> 
    </outbound> 
    </policies>
    

    Then, you can inherit the policy at the product and API scopes by using the base element as follows:

    <policies> 
    <inbound> 
    <base /> 
    <!-- other policy statements --> 
    </inbound> 
    </policies>
    
    
    

    please refer: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-policies?wt.mc_id=knwlserapi_inproduct_azportal#scopes

    do let me know incase of further queries, I would be happy to assist you.

    1 person found this answer helpful.