This is a long shot but has anyone worked with Bro...
# suitescript
k
This is a long shot but has anyone worked with Bronto's API where you can pull data from their system back into NetSuite for the analytical data on items? Going to have to get this setup but hoping someone has done something before to save a bit of time.
e
I’ve worked with the Bronto API. It uses SOAP.
k
Oh god really?? Brilliant News. Going to have figure it out not unless you have any pointers?
e
The first part would be to get a session id which is needed for all other requests to the API.
k
Not signed up to Bronto yet it's in process. Just need some overlay really on what to setup on the NetSuite side to pull data out.
e
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”&gt;‘; 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; } }
k
Thanks. I can rewrite that no problem.
Thanks for your help. Shame they don't deal in JSON.
e
Well they have a REST API but it’s limited to product and order data and that might be what you’re after.
k
No I need the analytical data for the products. So maybe I need the soap stuff.
Need to know the click data for date periods.
e
Ah ok yes you’ll need the SOAP API for that part.
k
I can then split by brand and create data for our partners we work with.
Thanks for your help.
e
readConversions is probably one of those that you’ll want to look into. https://help.bronto.com/bmp/reference/r_api_soap_readconversions.html
You can use xml2json.js to convert the XML data to JSON
Here’s a code snippet from my getContactActivities function var xmlDoc = nlapiStringToXML(body); var responseNode = nlapiSelectNode(xmlDoc, ‘/Envelope/Body/’ + soapResponse); var childNodes = nlapiSelectNodes(responseNode, ‘return’); for (var x = 0; x < childNodes.length; x++) { var activityNodes = childNodes[x]; var contactActivity = {}; //now that we have the nodes, we need to collect the childNodes and convert to an object var activities = xmlToJson(activityNodes); var contactActivity = {}; for (var activity in activities) { if (activities.hasOwnProperty(activity)) { eval(“contactActivity.” + activity + “=‘” + activities[activity][‘#text’] + “’;“); } } if (ObjectLength(contactActivity) > 0) { contactActivities.push(contactActivity); } }