Azure API Management - Validate query parameter with Named Values

Mouli Kaku 46 Reputation points
2021-02-23T11:34:40.887+00:00

Hi ,

TIA, I'm trying to validate Query Parameter with Named values using Transformation policy.

Named Value : allowedUserNames: "User1","User2",User3"

Policy

<policies>
<inbound>
<choose>
<when condition="@( !(new List<string>{{{allowedUserNames}}}.Any(c => c == context.Request.OriginalUrl.Query.GetValueOrDefault("userId"))))">
<return-response>
<set-status code="403" reason="Invalid user name" />
</return-response>
</when>
</choose>
<base />
<set-backend-service base-url="{{demoApiBackendBaseUrl}}" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>

When i compile this policy, i receive fallowing error.

Error:
One or more fields contain incorrect values
. Error in element 'choose' on line 16,coloumn 10 : 'Group' is a type,which is not valid in the given context.

Please let me know how to solve this.

Tia

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

1 answer

Sort by: Most helpful
  1. Nasreen Akter 10,736 Reputation points
    2021-02-23T16:00:19.373+00:00

    Hi @Mouli Kaku ,

    Everything looks good to me, except value in the NamedValue. I think you are missing ". Please try:

    "User1","User2","User3"   
    

    Hope this helps! :)

    ----------

    If the above response is helpful, please accept as answer and up-vote it. Thanks!