I've recently started a project where I'll need to make an HTTP Post request from NetSuite to a Boomi endpoint. I've found this really good example to go off of but it's missing what seem to be crucial libraries in step #8 for the SuiteScript to work properly.
The code below is what I've taken out and changed to try and suit my needs and it runs without error inside of NetSuite (as far as I can tell), but doesn't seem to make the connection to the endpoint. I'm hoping to find a simplified version of this to make the connection to the endpoint with basic auth and pass minimal XML/JSON data over.
function Customer_callBoomi()
{
var objType = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_object_type');
var BOOMI_USER = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_boomi_user');
var BOOMI_PASSWORD = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_boomi_password');
var BOOMI_URL = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_boomi_url');
try
{
/*Get Record Internal ID.*/
var customerId = nlapiGetRecordId();
var stInputXML = '<ID value=\"' + customerId + '\" type=\"' + objType + '\"/>';
/*create authentication header.*/
var arBoomiHeader = new Array();
var sAuthoizationString = Base64.encode(BOOMI_USER + ':' + BOOMI_PASSWORD);
arBoomiHeader['Content-Type']= 'application/xml';
arBoomiHeader["Authorization"] = "Basic " + sAuthoizationString;
// Suitelet invokes Boomi's real time integration workflow and receives response.
var objBoomiResponse = nlapiRequestURL(BOOMI_URL,stInputXML,arBoomiHeader);
// If there is no timout exception then
if (objBoomiResponse)
{
// if response status is Success
if ((objBoomiResponse.getCode() == '200') || (objBoomiResponse.getCode() == '201') || (objBoomiResponse.getCode() == '202'))
{
// Success!
} else {
// something bad happened
}
}
}
catch (e)
{
var stExceptionDetails = '';
if (e.getDetails != undefined)
{
stExceptionDetails = e.getCode() + ': ' + e.getDetails();
}
else
{
stExceptionDetails = e.toString();
}
}
}
This is the original code:
When I tried to run this without the aforementioned libraries I got an error similar to the one below except it said "logger". Which is why I went down the path of removing the mentions of that object to accommodate for the missing libraries:
// Script for Real Time Event Trigger
var stLoggerTitle = 'Real-Time Integration with BOomi';
function EmployeeUpsert_callBoomi(type)
{
var logger = new Logger();
logger.enableDebug();
logger.debug('Entry Log', 'Begin EmployeeUpsert_callBoomi');
var objType = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_object_type');
var BOOMI_USER = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_boomi_user');
var BOOMI_PASSWORD = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_boomi_password');
var BOOMI_URL = nlapiGetContext().getSetting('SCRIPT', 'custscriptset_value_boomi_url');
logger.debug('BOOMI_USER',BOOMI_USER);
logger.debug('BOOMI_PASSWORD', BOOMI_PASSWORD);
logger.debug('BOOMI_URL', BOOMI_URL);
try
{
/*Get Record Internal ID.*/
var sEmployeeRecIntId = nlapiGetRecordId();
var stInputXML = '<ID value=\"' + sEmployeeRecIntId + '\" type=\"' + objType + '\"/>';
logger.debug('Record ID', sEmployeeRecIntId);
logger.debug('Object Type', objType);
/*create authentication header.*/
var arBoomiHeader = new Array();
var sAuthoizationString = Base64.encode(BOOMI_USER + ':' + BOOMI_PASSWORD);
arBoomiHeader['Content-Type']= 'application/xml';
arBoomiHeader["Authorization"] = "Basic " + sAuthoizationString;
// Suitelet invokes Boomi's real time integration workflow and receives response.
logger.debug(stLoggerTitle, '['+new Date() + ']Initiate Boomi Request');
var objBoomiResponse = nlapiRequestURL(BOOMI_URL,stInputXML,arBoomiHeader);
logger.debug(stLoggerTitle, '['+new Date() + ']Process Boomi Response');
// If there is no timout exception then
if (objBoomiResponse)
{
logger.debug(stLoggerTitle,'HTTP Response Code=' + objBoomiResponse.getCode());
// if response status is Success
if ((objBoomiResponse.getCode() == '200') || (objBoomiResponse.getCode() == '201') || (objBoomiResponse.getCode() == '202'))
{
// Success!
} else {
// something bad happened
}
}
}
catch (e)
{
var stExceptionDetails = '';
if (e.getDetails != undefined)
{
stExceptionDetails = e.getCode() + ': ' + e.getDetails();
}
else
{
stExceptionDetails = e.toString();
}
// login execution logs
logger.error(stLoggerTitle, 'Exception Details: '+stExceptionDetails);
}
logger.debug('Exit Log', 'Exit EmployeeUpsert_callBoomi Successfully.');
}
Figured it out
Modified code: