동안 난은 세일즈 포스의 SOAP API를 (파트너 WSDL)를 사용하여 세일즈 포스에 Netsuite의 통합하려고합니다. Netsuite의 측면에서 은 내가 요청 받고 응답을 보낼 수있는 'N/HTTPS'모듈을 사용하고 있습니다. 먼저 Salesforce에 로그인 요청을 보내고 있으며 고유 세션 ID를 제공하고 있습니다. 지금 내가 얻은 세션 ID를 사용하여 영업 인력의 계정 레코드를 생성하는 요청을 보내려고 해요. 는 XML SOAP 메시지, 전에서 세션 ID 값 추가 해요 건설하는 동안 "항아리를 : 세션 ID 태그"합니다. HTTPS 요청을 전송하면 다음과 SOAP 오류 코드를 표시되어있을 경우 :Netsuite의 세일즈 포스 통합 : 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에 문제가있는 것 같지 않습니다. –
안녕하세요 kevin 님, XML 비누 메시지에 sessionId 요소가 추가로 없습니다. 두 번째 코드 블록, 나는 sessionId 값을 사용하면 urn.sessionId 태그 내에서 단일 문자열을 가지고 있기 때문에 언급했다. 올바르게 작동하고 있습니다. 예. ' tyuugfdsssf urn : sessionId>' 이렇게 사용하면 작동하지 않습니다. ''+ sessionId + ' urn : sessionId>'. 감사 –