'How to add #[payload] as value in the query params Mule 3

Unfortunately I haven't been able to solve it yet. I'd really appreciate it if someone could look into it. thanks everyone

I run into an issue with Mule 3 is that the payload is not recognized within the query params inside the HTTP request connector section.

This is because the query params must be quoted to be recognized as value. I've tried escaping the quotes and also saving the filter as a variable, but unfortunately that doesn't work either.

The filter must also be executed exactly otherwise get the full payload. So my final URL should be exactly like this otherwise it will not filter and I will get the full payload:

https://service.request.com/request/change/serviceRequest?$filter=id eq 5598f15c-e4fb-482f-ba41-0ced971ec737

Over the id I have the foreach which loops over each id and makes the request.

Below I have added the xml code.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp"
    xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns="http://www.mulesoft.org/schema/mule/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <http:request-config name="HTTP_Request_Configuration_1" host="service.request.com" port="443" doc:name="HTTP Request Configuration" />
    <objectstore:config name="ObjectStore__Connector_1" partition="timeStamp" persistent="true" doc:name="ObjectStore: Connector"/>
    <http:listener-config name="HTTP_Listener_Configuration_1" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="main_flow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
        <flow-ref name="time_now" doc:name="time_now"/>
        <flow-ref name="retrieve_and_save_time" doc:name="retrieve_and_save_time"/>
        <flow-ref name="dynamic_call" doc:name="dynamic_call"/>
        <flow-ref name="Store_after_succes" doc:name="Store_after_succes"/>
    </flow>
    <sub-flow name="time_now">
        <set-variable variableName="serverTime" value="#[server.dateTime.format(&quot;yyyy-MM-dd'T'HH:mm:ss'Z'&quot;)] " doc:name="Now Time"/>
    </sub-flow>
    
    <sub-flow name="retrieve_and_save_time">
        <objectstore:retrieve config-ref="ObjectStore__Connector" key="time" defaultValue-ref="#[(server.dateTime.plusHours(-2).format(&quot;yyyy-MM-dd'T'HH:mm:ss'Z'&quot;))]" doc:name="retrieve time last succes"/>
        <set-variable variableName="subTime" value="#[payload]" doc:name="save retrieve time in var"/>
    </sub-flow>
<sub-flow name="dynamic_call">
        <set-variable variableName="result" value="#[[]]" doc:name="set emtpy array"/>
        <set-payload value="[&quot;5598f15c-e4fb-482f-ba41-0ced971ec737&quot;, &quot;f6cb0890-3650-47c0-ba53-202229c8c5df&quot;, &quot;0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2&quot;]" doc:name="Payload Array" mimeType="application/java"/>

        <foreach  doc:name="For Each" >
            <http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Service Request">
                <http:request-builder>
                    <http:query-params expression="{&quot;?$filter&quot;: &quot;id eq #[payload]&quot;}"/>
                </http:request-builder>

            </http:request>
            <dw:transform-message doc:name="Append payload">
                <dw:set-variable variableName="result"><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-variable>
            </dw:transform-message>
        </foreach>
        <http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Request Ticket">
            <http:request-builder>
                <http:query-params expression="{&quot;?$filter&quot;: &quot;callDate lt #[flowVars.serverTime] and callDate gt #[flowVars.subTime]&quot;}"/>

            </http:request-builder>
        </http:request>

        <dw:transform-message doc:name="Append payload and set to JSON">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-payload>
        </dw:transform-message>
        <file:outbound-endpoint path="C:\Users" outputPattern="test.json" responseTimeout="10000" doc:name="File"/>
    </sub-flow>
<sub-flow name="Store_after_succes">
        <objectstore:store config-ref="ObjectStore__Connector" key="time" value-ref="#[server.dateTime.format(&quot;yyyy-MM-dd'T'HH:mm:ss'Z'&quot;)] " doc:name="ObjectStore"/>
    </sub-flow>
</mule>


Solution 1:[1]

You can add query Param like this. It will resolve the value of the payload and will not send the literal "#[payload] in the query param

<http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Service Request">
    <http:request-builder>
        <http:query-param paramName="$filter" value="id eq #[payload]"/>
    </http:request-builder>
</http:request>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1