I am attempting to run a script.js
with newman from a locally saved postman collection. In postman the call works, and returns a response body token that I need access to.
I don't care how the response body is returned I just don't want to open postman if I don't have to.
I keep encountering an error of ReferenceError: responseBody is not defined
Any help on this matter would be really appreciated.
$ node script.js
var newman = require('newman'); // require newman in your project
// call newman.run to pass `options` object and wait for callback
newman.run({
collection: require('./pathto/my_coll.postman_collection.json'),
reporters: 'cli'
}, function (err) {
if (err) { throw err; }
// console.log(responseBody);
JSON.parse(responseBody);
});
neither console.log
or JSON.parse
appear to be doing the trick because responseBody
doesn't appear to be defined from the start
exhausted references:
https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox
https://www.npmjs.com/package/newman
how to get whole html or json repsonse of an URL using Newman API