Home > Enterprise >  Azure APIM policy checking grater than or equal
Azure APIM policy checking grater than or equal

Time:09-28

In my poral I have query parameter call "PageSize" and I need to check that user input condition is grater and need to show message to user

than in my outbound section I put

<outbound>
    <choose>
         <when condition="@(context.Request.Url.Query.GetValueOrDefault("PageSize")) > = 20">
            <set-status code="205" reason="validation" />
            <set-body template="none">{"Message":"PageSize need to be less than 20"}</set-body>
        </when>
    </choose>
    <base />
</outbound>

but when i try to save the portal giving me following error message

One or more fields contain incorrect values:
Error in element 'choose' on line 21, column 10: Expression syntax is invalid.
       

CodePudding user response:

You have to define the complete condition inside condition="@().
This means this has not to be outside of brackets: > = 20

Please do not use a space between > =.
Correct: >=

The value from the query is string. You have to convert this value to an int.

Complete fixed outbound policy:

<outbound>
    <choose>
        <when condition="@(int.Parse(context.Request.Url.Query.GetValueOrDefault("PageSize")) >= 20) ">
            <set-status code="205" reason="validation" />
            <set-body template="none">{"Message":"PageSize need to be less than 20"}</set-body>
        </when>
    </choose>
    <base />
</outbound>
  • Related