Skip to content

Instantly share code, notes, and snippets.

@gjyoung1974
Created October 24, 2016 02:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjyoung1974/d256278023f43569a8d4982f309eedec to your computer and use it in GitHub Desktop.
Save gjyoung1974/d256278023f43569a8d4982f309eedec to your computer and use it in GitHub Desktop.
Call a SOAP API from Javascript
//post to a SOAP API
var http = require('http');
var s_Pan = '378282246310005'; //get the unprotected PAN from the form
var s_DPFormat = 'CC'; //get the data protection Format
var s_Identity = 'user@domain.com'; //get the data protection Format
var s_AuthInfo = 'p3ssw3rd'; //get the data protection Format
//Marshal up a ProtectFormattedData SOAP Mesage:
var soapRequest =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vib="http://voltage.com/vibesimple">' + "\n" +
' <soapenv:Header/>' + "\n" +
' <soapenv:Body>' + "\n" +
' <vib:ProtectFormattedData>' + "\n" +
' <dataIn>' + s_Pan + '</dataIn>' + "\n" +
' <format>' + s_DPFormat + '</format>' + "\n" +
' <identity>' + s_Identity + '</identity>' + "\n" +
' <tweak></tweak>' + "\n" +
' <authMethod>SharedSecret</authMethod>' + "\n" +
' <authInfo>' + s_AuthInfo + '</authInfo>' + "\n" +
' </vib:ProtectFormattedData>' + "\n" +
' </soapenv:Body>' + "\n" +
'</soapenv:Envelope>';
var options = {
hostname: 'voltage-pp-0000.corp.acme.local',
port: 8181,
path: '/vibesimple/services/VibeSimpleSOAP',
method: 'POST',
headers: {
//'Content-Type': 'text/xml; charset=utf-8', is it this one or the follwing one?
'Content-Type': 'application/soap+xml; charset=utf-8',
'SOAPAction': 'http://voltage.com/vibesimple'
}
};
var req = http.request(options, function (res) {
//TODO do something usefull with the response headers:
// console.log('headers:\n' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('body:\n' + chunk);
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment