Same policy have different behavior in azure apim

Akhila 0 Reputation points
2024-07-08T18:37:26.5966667+00:00

I have an Azure API Management policy that displays a warning when saved, but it functions correctly works for my needs.

User's image

But some clients encounter errors when saving, such as in the policy snippet below.

<set-variable name="labels" value="@{
                var labelsRaw = $"{{Labels}}".Split(',').Select(label => label.Trim().Split(':'));
                JObject labels = new JObject();
                foreach (string[] label in labelsRaw) {
                    if (label.Length == 2) {
                        labels.Add(label[0], label[1]);
                    }
                }
                if (labels.Count == 0) {
                    return "";
                }
                return $"\"labels\":{labels.ToString()},";
            }" />

User's image

Could you clarify why this issue happens?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,177 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
919 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 28,081 Reputation points
    2024-07-23T15:51:59.7633333+00:00

    @Akhila Thanks for reaching out. I tried saving the same policy at my end and i don't see any warnings the policy saved successfully
    User's image

    Note: As a best practice, it is recommended to copy and paste the policy into a text editor like Notepad to remove any formatting or whitespace that may cause issues when saving the policy in the Azure API Management portal.

    This can help to avoid errors or warnings that may occur due to formatting issues.

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.