Check image to view mule4 screen 我正在使用mule4构建集成流程,用于数据转换的Dataweave表达式以及用于测试HTTP调用的邮递员,我正在尝试从Dataweave中的以下XML获取0011x000014VegoAAC并将其插入到Salesforce记录中 一切正常,直到我添加了这两行(它们应该是从XML中提取0011x000014VegoAAC)
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>
完整的Dataweave代码
%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")
}]
错误
:Invalid status code: 400, response body: [{"message":"Cannot deserialize instance of reference from START_ARRAY value [line:1, column:423]","errorCode":"JSON_PARSER_ERROR"}]
在这两行之前,一切都很好[Mule4屏幕] [2]
我正在使用邮递员对该流进行HTTP调用
答案 0 :(得分:1)
这是HTTP 400错误。该描述表明某些应用程序正在尝试解析JSON输入。目前尚不清楚与您的DataWeave转换的关系,但是它输出的是Java,而不是JSON。可能您需要将输出更改为application / JSON。
更新:基于注释,您从PBSI__Customer__c返回一个具有某些ID的单个字符串,这将从问题中的DataWeave表达式返回一个列表,您需要获取第一个元素。您可以使用索引选择器[0]
来实现这一点,尽管我不知道是否可以保证有效载荷将始终只有一个元素。
PBSI__Customer__c: ((payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
filter (item) -> (item.@"attribute-id" == "sscAccountid")) [0]