0
votes

I am sending array list of Query params through HTTP request Array list id's [1234,3442,9489,9498]

    <http:request method="GET" config-ref="HTTP_Request_configuration" 
     path="${p.path}">
    <http:query-params><![CDATA[#[output application/java
    ---    {"id" : payload  }]]]>
   </http:query-params>

I am getting following error:

Error: java.util.ArrayList cannot be cast to > java.lang.String

Note: if i send them through for each, its working as expected. But i would like to pass them as list through query string params using IN operator in database

select Query:

   <flow name="query database"  > 
<set-variable value="#[attributes.queryParams.'id']" doc:name="ID"   variableName="ID"/>
<db:select doc:name="Get data"  config-ref="Db Connection">
  <db:sql >
   SELECT * from Mytable where id in ( :Ref) </db:sql>
                <db:input-parameters ><![CDATA[#[{
                    Ref: vars.ID
                }]]]></db:input-parameters>

    </db:select>

Workaround: Array list is converted to 1234,3442,9489,9498 using dataweave function reduce($+$$), yet returning error

Any ideas on how to pass array list with coma seperated values through query params and using them in IN clause of DB query

Edit: (payload joinBy ", ") as String helped me pass these values as string, Also changed type in RAML.

Now, how can i pass these values to DB to IN clause

1

1 Answers

0
votes

True you cannot pass an ArrayList as part of the query string as is. You will need to convert to comma-separated or similar to pass as part of the query string, just like you are doing with dataweave.

To use them as part of an IN query with expects an ArrayList you will need to convert he comma-separted list back to an ArrayList.

You can do this in Dataweave using splitBy function:

#[attributes.queryParams.'id' splitBy(",")]

Also noticed you are setting variable vPersonRef but referring to it as vars.ID doc:name is jsut for documentation. So you need to refer to it using the name attribute. so vars.vPersonRef not vars.ID(or rename it):

 <set-variable value="#[attributes.queryParams.'id']" doc:name="ID"   variableName="vPersonref"/>
...
vars.ID