Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Assign default value to query parameters

Not applicable

I am trying to assign a default value of the query parameter request.queryparam.results

I am using the query parameter in callouts but get 500 responses when request.queryparam.results=null.

If I use 'set' in Assign Message Policy I overwrite the value which is not what I won't if it is different from null.

How can I set a default value of the parameter?

Solved Solved
2 9 5,189
2 ACCEPTED SOLUTIONS

I really like using a simple javascript callout for this sort of thing. The ternary operator makes it pretty easy to one-line this.

context.setVariable('request.queryparam.results', context.getVariable('request.queryparam.results') ? context.getVariable('request.queryparam.results') : 0)

View solution in original post

Not applicable

This works for me in a single Assign Message and for multiple params @Anders Bilfeldt @Carlos Eberhardt

<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Default-Query-Params">
    <DisplayName>Assign Default Query Params</DisplayName>
    <FaultRules/>
    <Properties/>
    <AssignVariable>
        <Name>request.queryparam.format</Name>
      	<Value>json</Value>
      	<Ref>request.queryparam.format</Ref>
    </AssignVariable>
    <AssignVariable>
        <Name>request.queryparam.offset</Name>
      	<Value>0</Value>
      	<Ref>request.queryparam.offset</Ref>
    </AssignVariable>
    <AssignVariable>
        <Name>request.queryparam.limit</Name>
      	<Value>10</Value>
      	<Ref>request.queryparam.limit</Ref>
    </AssignVariable>
...

View solution in original post

9 REPLIES 9
Top Solution Authors