Last active
March 11, 2017 17:35
-
-
Save gjyoung1974/9573564832cac2718be962f33bc48465 to your computer and use it in GitHub Desktop.
erpm_checkout_credential.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
2016 Gordon Young, gjyoung1974@gmail.com | |
A node.js example for calling the LiebSoft ERPM REST API | |
This Javascript calls the DoLogin2 method | |
and returns an API token for calling further methods | |
*/ | |
var http = require('https'); //Call the API over HTTPS | |
//ignore Self-Signed SSL Certificate in test environment *** NEVER DO THIS IN PRODUCTION *** | |
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | |
// username and password to collect API Token | |
var sUsername = 'app1', sPassword = 'Password1!'; //TODO source this from somewhere else | |
//static user configured in DB only | |
//var DoLogin2Path = '/ERPMWebService/JSON/V2/AuthService.svc/DoLogin2'; | |
var DoLogin2Path = '//ERPMWebService/JSON/V2/AuthService.svc/AccountStoreOps_StoredCredential_CheckOut'; | |
//var auth_token_post_data = '{"LoginType": 1 ,"Password":"' + sPassword + '","Username":"' + sUsername + '"}'; | |
var auth_token_post_data = '{\ | |
"AuthenticationToken":"GGM32FI7CT503HOKAPKC9LLELNQ9MBLT",\ | |
"AccountIdentificationInfo":{\ | |
"AccountName":"ACME\\\\testapp",\ | |
"AccountStore":{\ | |
"CustomTypeName":"",\ | |
"TargetName":"DFW-VPD-PAMAPP1",\ | |
"Type":1\ | |
},\ | |
"PasswordList":""\ | |
},\ | |
"Comment":"test"\ | |
}'; | |
var options = { | |
hostname: '13.65.145.0', | |
port: 443, | |
path: DoLogin2Path , | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
} | |
}; | |
var req = http.request(options, function(res) { | |
//console.log('Status: ' + res.statusCode); | |
//console.log('Headers: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (body) { | |
console.log(JSON.parse(body).Password); | |
//console.log(JSON.parse(body).OperationMessage); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
req.write(auth_token_post_data); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment