How do you pass arrays in a QueryParam in an AssignMessage policy?

Not applicable

I want to pass an array as a query parameter. This is what I tried in an AssignMessagePolicy:

<QueryParam name="type[]">type_1</QueryParam>

<QueryParam name="type[]">type_2</QueryParam>

<QueryParam name="type[]">type_3</QueryParam>

However, the only thing that was passed was type[]=type_3. Is there a way to get this to convert into the url array format: type[]=type_1&type[]=type_2&type[]=type_3.

Note that in the actual request uri, [] = %5B%5D.

Solved Solved
1 2 2,128
1 ACCEPTED SOLUTION

It's somewhat bothersome that the <QueryParam> element does not behave the way you think it does. But there is an easy workaround.

Instead of this AssignMessage, which does not work as intended:

<AssignMessage name='AssignMessage-1'>
  <AssignTo createNew='false' type='request'/>
  <Set>
    <QueryParams>
      <!-- only the last value will be set -->
      <QueryParam name="key">value_1</QueryParam>
      <QueryParam name="key">value_2</QueryParam>
      <QueryParam name="key">value_3</QueryParam>
    </QueryParams>
    <Verb>GET</Verb>
  </Set>
</AssignMessage>

You can use this:

<AssignMessage name='AssignMessage-4'>
  <AssignVariable>
    <Name>request.uri</Name>
    <Value>/?key=value_1&key=value_2&key=value_3</Value>
  </AssignVariable>
</AssignMessage>

the variable 'request.uri' must include the path AND the query string, so be sure to include the path and the required initial question mark. Also escape any ampersands.

If you don't like the mechanism using AssignMessage, you can use a JavaScript callout to do the equivalent.

View solution in original post

2 REPLIES 2

remeeshnair
Participant IV

I guess the name should be unique. You can give multiple parameters with unique names.

Regards,

Remeesh.

It's somewhat bothersome that the <QueryParam> element does not behave the way you think it does. But there is an easy workaround.

Instead of this AssignMessage, which does not work as intended:

<AssignMessage name='AssignMessage-1'>
  <AssignTo createNew='false' type='request'/>
  <Set>
    <QueryParams>
      <!-- only the last value will be set -->
      <QueryParam name="key">value_1</QueryParam>
      <QueryParam name="key">value_2</QueryParam>
      <QueryParam name="key">value_3</QueryParam>
    </QueryParams>
    <Verb>GET</Verb>
  </Set>
</AssignMessage>

You can use this:

<AssignMessage name='AssignMessage-4'>
  <AssignVariable>
    <Name>request.uri</Name>
    <Value>/?key=value_1&key=value_2&key=value_3</Value>
  </AssignVariable>
</AssignMessage>

the variable 'request.uri' must include the path AND the query string, so be sure to include the path and the required initial question mark. Also escape any ampersands.

If you don't like the mechanism using AssignMessage, you can use a JavaScript callout to do the equivalent.