gpt4 book ai didi

node.js - 如何指定xsi :type for an element in SOAP request using node-soap

转载 作者:行者123 更新时间:2023-12-02 21:23:26 25 4
gpt4 key购买 nike

我尝试使用 Node 调用 Create 方法,将名为 ObjectsTriggeredSend 类型对象传递到 ExactTarget SOAP Web 服务- SOAP 包。

我需要创建如下所示的内容(请注意 xsi:type="ns0:TriggeredSend"):

<SOAP-ENV:Envelope xmlns:etns="http://exacttarget.com" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns0="http://exacttarget.com/wsdl/partnerAPI" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<ns1:Body>
<ns0:CreateRequest>
<ns0:Objects xsi:type="ns0:TriggeredSend">
<ns0:TriggeredSendDefinition>
<ns0:CustomerKey>abc</ns0:CustomerKey>
</ns0:TriggeredSendDefinition>
</ns0:Objects>
</ns0:CreateRequest>
</ns1:Body>
</SOAP-ENV:Envelope>

通过下面的代码,我接近了:

var soap = require('soap')

soap.createClient(url, function(err, client){
client.Create({
Objects: {
TriggeredSendDefinition: {
CustomerKey: 'abc'
}
},
function(err, response) {})
});
});

这给了我这个(没有xsi:type):

<ns0:CreateRequest>
<ns0:Objects>
<ns0:TriggeredSendDefinition>
<ns0:CustomerKey>abc</ns0:CustomerKey>
</ns0:TriggeredSendDefinition>
</ns0:Objects>
</ns0:CreateRequest>

如何指定 Objects 元素的 TriggeredSend 类型?

最佳答案

您可以添加一个特殊的attributes Node 来指定xsi:type:

var soap = require('soap')

soap.createClient(url, function(err, client){
client.Create({
Objects: {
attributes: {
xsi_type: {
type: 'TriggeredSend',
xmlns: 'http://exacttarget.com/wsdl/partnerAPI'
}
}
TriggeredSendDefinition: {
CustomerKey: 'abc'
}
},
function(err, response) {})
});
});

产生:

<ns0:CreateRequest>
<ns0:Objects xsi:type="ns0:TriggeredSend">
<ns0:TriggeredSendDefinition>
<ns0:CustomerKey>abc</ns0:CustomerKey>
</ns0:TriggeredSendDefinition>
</ns0:Objects>
</ns0:CreateRequest>

关于node.js - 如何指定xsi :type for an element in SOAP request using node-soap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26183063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com