SalesForce SOAP API(Partner WSDL)を使用してNetsuiteをSalesforceに統合しようとしています。 Netsuite側では、私は 'N/https'モジュールを使用してリクエストを送信し、応答を得ています。 まず、Salesforceにログインリクエストを送信していて、一意のセッションIDを与えています。 これで、取得したセッションIDを使用してsalesforceでアカウントレコードを作成するようにcreateリクエストを送信しようとしています。 XML SOAPメッセージの作成中に 「urn:SessionIdタグ」にセッションID値を追加しています。 HTTPSリクエストを送信すると、次のSOAPフォルトコードを示している間:NetsuiteからSalesforceへの統合:SOAP APIフォルトコード:単純なタイプの逆シリアル化中に予期せぬ要素{} sessionId
エラーメッセージ:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>Unexpected element {}sessionId during simple type deserialization</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>"
}
マイコード:
スイートスクリプトバージョン:2.0、タイプ:ユーザイベント、方法:送信後、モジュール: 'N/https'
function afterSubmit(scriptContext) {
var customerRec = scriptContext.newRecord ;
var customerName = customerRec.getText('entityid');
log.debug('customerName : ',customerName);
//SOAP Login Request
var postData = '';
var header=[];
var apiURL = '';
var response = '';
var strSOAPLoginRequest="";
strSOAPLoginRequest += "<soapenv:Envelope xmlns:soapenv=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:urn=\"urn:partner.soap.sforce.com\">";
strSOAPLoginRequest += " <soapenv:Header>";
strSOAPLoginRequest += " <\/soapenv:Header>";
strSOAPLoginRequest += " <soapenv:Body>";
strSOAPLoginRequest += " <urn:login>";
strSOAPLoginRequest += " <urn:username>myloginid<\/urn:username>";
strSOAPLoginRequest += " <urn:password>mypwd<\/urn:password>";
strSOAPLoginRequest += " <\/urn:login>";
strSOAPLoginRequest += " <\/soapenv:Body>";
strSOAPLoginRequest += "<\/soapenv:Envelope>";
postData = strSOAPLoginRequest;
header['Content-Type']='text/xml';
header['SOAPAction']='https://login.salesforce.com/services/Soap/u/41.0';
apiURL='https://login.salesforce.com/services/Soap/u/41.0';
try{
response=https.post({
url:apiURL,
headers:header,
body:postData
});
response = JSON.stringify(response);
log.debug("Login-Respone:", response+ ', Type:'+typeof response);
var getSessionIdStartIndex = response.indexOf("<sessionId>");
log.debug('getSessionIdStartIndex:',getSessionIdStartIndex);
var getSessionIdEndIndex = response.indexOf("</sessionId>");
log.debug('getSessionIdEndIndex:',getSessionIdEndIndex);
var ressessionValue= response.substring(getSessionIdStartIndex, getSessionIdEndIndex);
ressessionValue = ressessionValue.replace(/^\s+|\s+$/g, "");
log.debug('resSessionId:',ressessionValue + 'Type:'+typeof ressessionValue);
header = [];
// SOAP CREATE ACTION REQUEST
header['Content-Type']='text/xml';
header['SOAPAction']= 'https://ap5.salesforce.com/services/Soap/u/41.0/00D7F0xxxx';
apiURL='https://ap5.salesforce.com/services/Soap/u/41.0/'+'007xxxx';
//apiURL=res_serverUrl;
var strSOAPCreateActionXml="";
strSOAPCreateActionXml += "<soapenv:Envelope xmlns:soapenv=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:urn=\"urn:partner.soap.sforce.com\" xmlns:urn1=\"urn:sobject.partner.soap.sforce.com\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\">";
strSOAPCreateActionXml += " <soapenv:Header>";
strSOAPCreateActionXml += " <urn:SessionHeader>";
strSOAPCreateActionXml += "<urn:sessionId>"+ressessionValue+"<\/urn:sessionId>";
strSOAPCreateActionXml += "<\/urn:sessionId>";
strSOAPCreateActionXml += " <\/urn:SessionHeader>";
strSOAPCreateActionXml += " <\/soapenv:Header>";
strSOAPCreateActionXml += " <soapenv:Body>";
strSOAPCreateActionXml += " <urn:create>";
strSOAPCreateActionXml += " <urn:sObjects xsi:type=\"urn1:Account\">";
strSOAPCreateActionXml += " <Name>"+customerName+"<\/Name>";
strSOAPCreateActionXml += " <AccountNumber>4567<\/AccountNumber>";
strSOAPCreateActionXml += " <\/urn:sObjects>";
strSOAPCreateActionXml += " <\/urn:create>";
strSOAPCreateActionXml += " <\/soapenv:Body>";
strSOAPCreateActionXml += "<\/soapenv:Envelope>";
postData = strSOAPCreateActionXml;
var responseCreate = https.post({
url:apiURL,
headers:header,
body:postData
});
responseCreate = JSON.stringify(responseCreate);
log.debug("CreateAction-Respone:", responseCreate+ ', Type:'+typeof responseCreate);
}catch(err){
log.error('ERROR',err.message);
}
}
上記のコードブロックのようにsessionIdの値を代入するのではなく、私の最初のコードブロックでのセッションIDタグ:私は以下のコードブロックのようにセッションID値ラインを交換する場合には、代わりに間違い骨壷の値であるか疑問に思う正しく
var strVar="";
strVar += " <urn:sessionId>AQ8AQJCeR3ViMdN48UXWfDD0SiMbW5K6JOz3a0K6DhXt63pp54PsKOpoiMh.8mnw7bJxe0hQoyrCbRZtk0kmliNFfIntRAQb<\/urn:sessionId>";
作業を意味します。
私の質問は、構築XMLのSOAPメッセージに予め
感謝を動的に取得したセッション値を構築する方法です。あなたが必要とするように
あなたは余分な/ urn:sessionIdが問題であるかどうかわからない –
こんにちはケビン、私はXMLのsoapメッセージにsessionId要素を追加していません。 2番目のコードブロック、私はsessionId値を使用する場合はurn.sessionIdタグ内の単一の文字列を持っているので、私は述べた。正常に動作しています。例: ' tyuugfdsssf urn:sessionId>'のようになります。このように使用すると、動作していないことを意味します。 '' + sessionId + ' urn:sessionId>'ありがとう –