Here’s a SS 1.0 version. Haven’t had the chance to write the SS 2.0 version.
/* returns a sessionid after a successful login */
function connectToBrontoAPI() {
try {
var brontoEndPoint = ’
https://api.bronto.com/v4?wsdl';
var headers = {“Accept”: “application/xml”,
“Content-Type”: “text/xml, charset=‘utf-8’“,
“SOAPAction” : “login”,
};
//soap call based on
https://github.com/savonrb/savon/issues/343
var xmlBody = ‘<?xml version=“1.0” encoding=“utf-8" ?>‘;
xmlBody += ‘<soapenv:Envelope xmlns:xsd=“
http://www.w3.org/2001/XMLSchema” xmlns:xsi=“
http://www.w3.org/2001/XMLSchema-instance” xmlns:v4=“
http://api.bronto.com/v4” xmlns:soapenv=“
http://schemas.xmlsoap.org/soap/envelope/” xmlns:ins0=“
http://api.bronto.com/v4”>‘;
xmlBody += ‘<soapenv:Header>‘;
xmlBody += ‘</soapenv:Header>‘;
xmlBody += ‘<soapenv:Body>‘;
xmlBody += ‘<ins0:login>‘;
xmlBody += ‘<apiToken>YourAPITokenHere</apiToken>‘;
xmlBody += ‘</ins0:login>‘;
xmlBody += ‘</soapenv:Body>‘;
xmlBody += ‘</soapenv:Envelope>’;
//the sessionid is in the return element
var response = nlapiRequestURL(brontoEndPoint, xmlBody, headers, ‘POST’);
//using xpath get the sessionId and return it
//remove the colons since NS can’t handle it
var body = response.getBody().replaceAll(‘ns2:‘, ‘’).replaceAll(‘soap:‘,’‘);
var xmlDoc = nlapiStringToXML(body);
var responseNode = nlapiSelectNode(xmlDoc, ‘/Envelope/Body/loginResponse’);
var sessionId = nlapiSelectValue(responseNode, ‘return’);
return sessionId;
}
catch (ex) {
nlapiLogExecution(‘ERROR’, ‘ocapiConnectToBrontoAPI ’ + ex.message);
return null;
}
}