1

How to do mapping for below data.

ParameterMap{[card=[15242424211], phone=[54545454545]]}

This data is dynamic which is coming from http request as part queryparameters. I want to form query params in the form #[{'p1':'v1', 'p2':'v2'}] dynamically

for example into [{'card': '15242424211','phone':'54545454545'}]

i.e Array of maps(application/java) Using Dataweave in mule can you please help on this

Gopi
  • 105
  • 1
  • 7
  • 24

1 Answers1

1

use following code

%dw 1.0
%output application/json
---
inboundProperties."http.query.params" mapObject {
    ($$) : $[0]
}

With this output will be {"card": "15242424211","phone":"54545454545"} you can wrap it under array if required by using

%dw 1.0
%output application/json
---
[inboundProperties."http.query.params" mapObject {
    ($$) : $[0]
}]

This will produce output as [{"card": "15242424211","phone":"54545454545"}] Please refer org.mule.module.http.internal.ParameterMap for details of HTTP params.

Hope this help.

Update:- Please use following for setting query parameters for HTTP outbound request.

<dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
inboundProperties."http.query.params" mapObject {
    ($$) : $[0]
}
]]></dw:set-payload>
        </dw:transform-message>
AnupamBhusari
  • 2,395
  • 2
  • 14
  • 22
  • Getting below error when i am hitting outbound HTTP with query param ...Length Required

    Length Required


    HTTP Error 411. The request must be chunked or have a content length.

    .. can you please help on this
    – Gopi Sep 08 '17 at 10:28
  • as per below link format(should be map). For testing i have hardcoded data and tested. Even after it is not working https://docs.mulesoft.com/mule-user-guide/v/3.7/http-request-connector#adding-custom-parameters – Gopi Sep 08 '17 at 10:30
  • Please check undated answer. I have tested it and working fine for me. – AnupamBhusari Sep 08 '17 at 10:39
  • Mapping is working well but http queryparams expression is not accepting format. can you please help – Gopi Sep 08 '17 at 10:49
  • Please post code snippet of dataweave and http request. – AnupamBhusari Sep 08 '17 at 12:03