Using Named Values in Policy XML files

Dev S 26 Reputation points
2022-10-28T01:41:36.917+00:00

Azure Portal seems to return an error when using a named-value as part (not as whole) of an attribute value. However, using the Azure APIM VS Code extension doesn't have any trouble publishing the policy.xml for an API which has such a setting and the API is also working as expected.

Is this expected behavior by Azure Portal?

For example using

   <set-backend-service id="apim-generated-policy" backend-id="ECHO_{{Backend-ENV-ID}}" />  

in policy.xml for an API through VS Code works, but, Azure Portal returns an error when browsing through the same API after an update. The error shown is

   API Management.  
   Could not load policies. Please try again later.  
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,908 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Dev S 26 Reputation points
    2024-02-29T21:42:28.2966667+00:00

    Not sure if my previous comment was posted successfully, so reposting here: I think we might still have a problem with the editor on Azure Portal. Now when using Named Values in a Policy, the online Editor complains that we need to include an @ before an Expression. However, for Named Values used in a policy, the documentation does not specify this and it makes sense. For example:

    <set-backend-service id="apim-generated-policy" backend-id="ECHO_{{Backend-ENV-ID}}" />  
    
    

    (above is NOT accepted in the Azure Portal Editor)

    is not the same as

    <set-backend-service id="apim-generated-policy" backend-id="ECHO_@{{Backend-ENV-ID}}" />  
    
    

    (above is accepted in the Azure Portal Editor)

    We are able to successfully use Set-AzApiManagementPolicy to upload a policy without the @ before {{}} when specifying a Named Value.

    0 comments No comments