Reputation: 59
Check image to view mule4 screen I am using mule4 to build integration flow, Dataweave expression for data transformation and postman to test HTTP call, I am trying to get 0011x000014VegoAAC from XML below in Dataweave and insert into Salesforce record Everything was working fine until I added these two lines(they are suppose to extract 0011x000014VegoAAC from XML)
PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
filter (item) -> (item.@"attribute-id" == "sscAccountid")
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
<order-date>2020-07-10T08:57:05.076Z</order-date>
<current-order-no>00000907</current-order-no>
<product-lineitems>
<product-lineitem>
<net-price>54.17</net-price>
</product-lineitem>
</product-lineitems>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
</custom-attributes>
</order>
Full Dataweave code
%dw 2.0
output application/java
ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
---
[{
Ascent4Ecomm__Ecomm_Order_ID__c: payload.ns0#order.ns0#"original-order-no",
Ascent4Ecomm__Ecomm_Order_Name__c: payload.ns0#order.ns0#"original-order-no",
Ascent4Ecomm__Ecomm_Order_Number__c: payload.ns0#order.ns0#"original-order-no",
attributes: {
"type": "PBSI__PBSI_Sales_Order__c",
"referenceId": "SO"
},
PBSI__Sales_Order_Lines__r: {
records: payload.ns0#order.ns0#"product-lineitems".*ns0#"product-lineitem" map ( e , empindex ) -> {
"attributes": {
"type": "PBSI__PBSI_Sales_Order_Line__c",
"referenceId": e.ns0#"product-id"
},
"PBSI__Item__c": e.ns0#"custom-attributes".ns0#"custom-attribute",
"PBSI__ItemDescription__c": e.ns0#"product-name"
}
},
***These two lines throws error:***
PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
filter (item) -> (item.@"attribute-id" == "sscAccountid")
}]
error
:Invalid status code: 400, response body: [{"message":"Cannot deserialize instance of reference from START_ARRAY value [line:1, column:423]","errorCode":"JSON_PARSER_ERROR"}]
Everything was working fine before those two lines[Mule4 screen][2]
I am using postman to make HTTP call to that flow
Upvotes: 0
Views: 530
Reputation: 25872
That is an HTTP 400 error. The description indicates that some application is trying to parse a JSON input. It is unclear the relationship with your DataWeave transformation, however it is outputting Java, not JSON. Probably you need to change the output to application/JSON instead.
UPDATE: Based on the comments, you from PBSI__Customer__c to return a single string with some id, which is returning a list from the DataWeave expression in the question, you need to get the first element. You can get that with the index selector [0]
, though I don't know if it is guaranteed that the payload will always have a single element.
PBSI__Customer__c: ((payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
filter (item) -> (item.@"attribute-id" == "sscAccountid")) [0]
Upvotes: 1