我正在尝试在 Netsuite 的 API SuiteTalk 上创建请求,但发现自己陷入了一个简单的请求,即将文件(在我的 fileCabinet 中)附加到发票,请参阅下面的我的请求,然后是我得到的响应。
特别奇怪的是,该格式也像我在研究答案时在 SuiteAnswers 上找到的格式。
<soapenv:Envelope
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:platformCore='urn:core_2019_2.platform.webservices.netsuite.com'
xmlns:platformMsgs='urn:messages_2019_2.platform.webservices.netsuite.com'>
<soapenv:Header>
<tokenPassport>
<account>{{ACCOUNT}}</account>
<consumerKey>{{CONSUMER_KEY}}</consumerKey>
<token>{{TOKEN_ID}}</token>
<nonce>{{nonce}}</nonce>
<timestamp>{{timestamp}}</timestamp>
<signature algorithm="HMAC-SHA1">{{signature}}</signature>
</tokenPassport>
</soapenv:Header>
<soapenv:Body>
<attach xsi:type='platformMsgs:AttachRequest'>
<attachReference xsi:type='platformCore:AttachBasicReference'>
<attachTo xsi:type='platformCore:RecordRef' internalId='1261476' type='invoice'></attachTo>
<attachedRecord xsi:type='platformCore:RecordRef' internalId='413612' type='file'></attachedRecord>
</attachReference>
</attach>
</soapenv:Body>
</soapenv:Envelope>
回应
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>The request could not be understood by the server due to malformed syntax.</faultstring>
<detail>
<platformFaults:invalidCredentialsFault xmlns:platformFaults="urn:faults_2019_2.platform.webservices.netsuite.com">
<platformFaults:code>USER_ERROR</platformFaults:code>
<platformFaults:message>The request could not be understood by the server due to malformed syntax.</platformFaults:message>
</platformFaults:invalidCredentialsFault>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">partners011</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
编辑:这是 WSDL
<message name="attachRequest">
<part name="parameters" element="platformMsgs:attach"/>
</message>
平台留言:
<complexType name="AttachRequest">
<sequence>
<element name="attachReference" type="platformCore:AttachReference" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
<element name="attach" type="platformMsgs:AttachRequest"/>
用于附加的平台核心:
<!-- ******************************************************************** -->
<!-- Attach -->
<!-- ******************************************************************** -->
<complexType name="AttachReference" abstract="true">
<sequence>
<element name="attachTo" type="platformCore:BaseRef" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
<complexType name="AttachBasicReference">
<complexContent>
<extension base="platformCore:AttachReference">
<sequence>
<element name="attachedRecord" type="platformCore:BaseRef" minOccurs="1" maxOccurs="1"/>
</sequence>
</extension>
</complexContent>
</complexType>
<!-- attach/end -->
BaseRef 的平台核心
<complexType name="BaseRef" abstract="true">
<sequence>
<element name="name" type="xsd:string" minOccurs="0"/>
<!-- record name -->
</sequence>
</complexType>
<element name="baseRef" type="platformCore:BaseRef"/>
RecordRef 的平台核心:
<complexType name="RecordRef">
<complexContent>
<extension base="platformCore:BaseRef">
<attribute name="internalId" type="xsd:string"/>
<attribute name="externalId" type="xsd:string"/>
<attribute name="type" type="platformCoreTyp:RecordType"/>
<!-- primary record internalId -->
<!-- record type -->
</extension>
</complexContent>
</complexType>
我发现 Netsuite 不支持 HMAC-SHA1,所以我切换到 HMAC-SHA256,现在它可以工作了,我还切换到 2021_2 WSDL。
对于 Postman 上的 SHA256 签名,可以在互联网上找到资源。
<soapenv:Envelope
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:platformCore='urn:core_2021_2.platform.webservices.netsuite.com'
xmlns:platformMsgs='urn:messages_2021_2.platform.webservices.netsuite.com'>
<soapenv:Header>
<tokenPassport>
<account>{{ACCOUNT}}</account>
<consumerKey>{{CONSUMER_KEY}}</consumerKey>
<token>{{TOKEN_ID}}</token>
<nonce>{{nonce}}</nonce>
<timestamp>{{timestamp}}</timestamp>
<signature algorithm="HMAC-SHA256">{{signature}}</signature>
</tokenPassport>
</soapenv:Header>
<soapenv:Body>
<attach xsi:type='platformMsgs:AttachRequest'>
<attachReference xsi:type='platformCore:AttachBasicReference'>
<attachTo xsi:type='platformCore:RecordRef' internalId='1261476' type='invoice'></attachTo>
<attachedRecord xsi:type='platformCore:RecordRef' internalId='413612' type='file'></attachedRecord>
</attachReference>
</attach>
</soapenv:Body>
</soapenv:Envelope>