Liquid template Minus operation not working

Thomas Moeller 26 Reputation points

My issue is similar to already described ones, but I can't see if it has already been / when it will be fixed:

I need to create an outbound policy in Azure APIM where I need to subtract something from a variable, e.g.:

"PageIndexnew": {{body.page_index | Plus:1}}

If the page index has e.g. the value 2 above code returns "21" instead of "3" as expected.

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

Accepted answer
  1. MayankBargali-MSFT 69,851 Reputation points

    @Thomas Moeller Thanks for reaching out and I have reached out to my team if this is the expected behavior/limitation. It looks like yours body.page_index has the value of string type and not integer.
    When the value is of type string then it appends the two values but in case if it is integer value then it adds the two values.

    <set-body template="liquid">
    <cust>{<!-- -->{ 5 | Plus: 1 }}</cust>

    "output": "<cust>6</cust>"

    <set-body template="liquid">
    <cust>{<!-- -->{ "5" | Plus: 1 }}</cust>

    **Output: **
    "output": "<cust>51</cust>"

    **Update: **
    I got the confirmation from my team unfortunately as of now, if you have string value and leverage the Plus within liquid, then APIM treats it as string and appends it and the above expression output is expected outcome as of now.

    @Thomas Moeller Thanks for sharing the workaround.
    You have created the policy in outbound section to declare the int variable using set-variable and leverage this variable in your outbound policy of the liquid template

    <set-variable name="newindexasint" value="@(int.Parse(context.Response.Body.As<JObject>(preserveContent: true)["page_index"].ToString()))" />
    "PageIndex": {{ context.Variables["newindexasint"]|Plus: 1 }}

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful