Sunday, 2 December 2018

Node "https" returning different value from postman call

Making a postman call to a remote API, `https://10.0.0.100/api/policies\` with an auth token and it returns some nice json:{ "policies": [ { "rules": [ { "ruleId": -4325354696963955582, "description": "When a device is NAT, its other classifications may be inaccurate. Therefore, we put the NAT detection first.", "name": "NAT Devices" }, { "ruleId": -1408393082453523984, "description": "If positive ID, it will have a comment", "name": "No Comment" }, { "ruleId": -2125719484886170917, "description": "", "name": "Macintosh" }, { "ruleId": -5483870396383581964, "description": "", "name": "Windows" }, { "ruleId": 2739756470947467673, "description": "", "name": "Printers" }, { "ruleId": 3229735550052762596, "description": "", "name": "VoIP Devices" }, { "ruleId": 5371620092481458164, "description": "", "name": "Network Devices" }, { "ruleId": -4871103186337869878, "description": "", "name": "Linux\\Unix" }, { "ruleId": 3824851944761336864, "description": "", "name": "Mobile Devices" }, { "ruleId": 2843599815087612770, "description": "", "name": "Approved Misc Devices" }, { "ruleId": -6628632941374138956, "description": "", "name": "Unclassified" } ], "description": "", "policyId": 7706332631422080339, "name": "1.1 Asset Classification" }, Notice the policyID and RuleID's that are returned.Now, I am also making the same call with node, using https. Side note, the getToken() just returns a JWT.var options = { hostname: ctIP, path: '/api/login', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, rejectUnauthorized: false }; function getPolicies(options, eventCallback) { getToken(options, function (token) { options.path = '/api/policies' options.method = 'GET' options.headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': token } getData(options, function (data) { eventCallback(data); }); }); } function getData(options, eventCallback) { var req = https.request(options, function(res) { var body = ''; res.on('data', function (chunk) { body += chunk; }); res.on('end', function () { var jsonResult = JSON.parse(body); //console.log(body) eventCallback(jsonResult); }); }).on('error', function (e) { console.log('Got error: ', e); }); req.end(); } The return from the node call is below, a few differences... which is where the mystery begins.{ rules: [ { ruleId: -4325354696963955700, description: 'When a device is NAT', name: 'NAT Devices' }, { ruleId: -1408393082453524000, description: 'If positive ID, it will have a comment', name: 'No Comment' }, { ruleId: -2125719484886171000, description: '', name: 'Macintosh' }, { ruleId: -5483870396383582000, description: '', name: 'Windows' }, { ruleId: 2739756470947468000, description: '', name: 'Printers' }, { ruleId: 3229735550052762600, description: '', name: 'VoIP Devices' }, { ruleId: 5371620092481458000, description: '', name: 'Network Devices' }, { ruleId: -4871103186337870000, description: '', name: 'Linux\\Unix' }, { ruleId: 3824851944761337000, description: '', name: 'Mobile Devices' }, { ruleId: 2843599815087613000, description: '', name: 'Approved Misc Devices' }, { ruleId: -6628632941374139000, description: '', name: 'Unclassified' } ], description: '', policyId: 7706332631422080000, name: '1.1 Asset Classification' } Sorry about the JSON view on this one, it's a level down.Check it out,policyId from Node is 7706332631422080000 and from Postman 7706332631422080339Some RuleId's to compare:NodePostman-6628632941374139000-6628632941374138956284359981508761300028435998150876127703824851944761337000382485194476133686427397564709474680002739756470947467673It appears that Node is rounding these ID's as if they were numbers. I verified the rounded ID's are in the getData body, and not a result of the JSON.parse(body).Any ideas?

Submitted December 03, 2018 at 03:16AM by Jacksonp2008

No comments:

Post a Comment