NetSuite Development Notes
Thursday, June 20, 2019
Invoke Web Services using nlapiRequestURL
Below is a sample script that invokes a Web Services request using the nlapiRequestURL API:
function suitelet(request, response){ var endPoint = 'https://webservices.na1.netsuite.com/services/NetSuitePort_2013_2'; var stSoapAction = 'get'; var soapHeaders = new Array(); soapHeaders['Host'] = "webservices.na1.netsuite.com"; soapHeaders['Content-Type'] = 'text/xml; charset=utf-8'; soapHeaders['SOAPAction'] = stSoapAction; try{ email = 'webservices_mcelosa@lparadise.com'; password = '*********'; account = 'ACCT001'; var soap=''; soap += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'; soap += '<soapenv:Header>'; soap += '<platformMsgs:passport'; soap += ' xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"'; soap += ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'; soap += ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; soap += ' xmlns:platformCore="urn:core_2013_2.platform.webservices.netsuite.com"'; soap += ' xmlns:platformMsgs="urn:messages_2013_2.platform.webservices.netsuite.com">'; soap += '<platformCore:email>' + email + '</platformCore:email>'; soap += '<platformCore:password>' + password + '</platformCore:password>'; soap += '<platformCore:account>' + account + '</platformCore:account>'; soap += '</platformMsgs:passport>'; soap += '</soapenv:Header>'; soap += '<soapenv:Body>'; soap += '<platformMsgs:get'; soap += ' xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"'; soap += ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'; soap += ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; soap += ' xmlns:s0="urn:core_2013_2.platform.webservices.netsuite.com"'; soap += ' xmlns:platformMsgs="urn:messages_2013_2.platform.webservices.netsuite.com">'; soap += '<platformMsgs:baseRef xsi:type="s0:RecordRef" internalId="1386" type="inventoryItem" />'; soap += '</platformMsgs:get>'; soap += '</soapenv:Body>'; soap += '</soapenv:Envelope>'; var requestServer = nlapiRequestURL(endPoint, soap, soapHeaders); nlapiLogExecution('DEBUG', 'requestServer ' , requestServer.getBody()); var soapResponse = nlapiStringToXML(requestServer.getBody()); response.write('HTTP Code: ' + requestServer.getCode() + '\n' + 'Body: \n' + requestServer.getBody()); }catch(e){ nlapiLogExecution('DEBUG', 'Exception ' + e.message ); nlapiLogExecution('DEBUG', 'Exception ' + e.name); nlapiLogExecution('DEBUG', 'Exception ' + e.toString()); }}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment