Getaddrinfo ENOTFOUND {{host}}{{version}} revisited

Here’s my script. Well, at least the important part.

require('dotenv').config();
const { Console } = require('console');
const newman = require('newman'); // require newman in your project
const key = process.env.postman_api_key;

// The signature for the run function is newman.run(options: object , callback: function) => run: 
EventEmitter
newman.run(
{
    //collection: require('.\\Orders_1.postman_collection.json'),
	collection: 'https://api.getpostman.com/collections/13204628-74a6e824-c8d1-45fd-83e8-8a9003304b37?apikey=' + key,
    environment: require('.\\localHost.postman_environment.json'),
    //environment: 'https://api.getpostman.com/environments/12415606-e03e06c1-00f4-422a-891a-4e6984aa7cf3?apikey=' + key,
	reporters: 'htmlextra', // htmlextra is a reporting package for newman that will require installlation using NPM.
    reporter: 
	{ //Go here for documentation: https://www.npmjs.com/package/newman-reporter-htmlextra
		htmlextra: //Report options
		{
			export: '.\\Results.html', //Directory and name
			template: '.\\InnovaAPITemplate.hbs', //Template used for report. Html, CSS and JS are all embedded.
			title: 'Innovations API',
			showEnviornmentData: true,
			browserTitle: "Innovations API",
			showMarkdownLinks: true,                
			showFolderDescription: true,
            //skipSensitiveData: true //Hides request header because it can contain the authorization tokens.               
		}
	}
},// <-- End of options object
function (err,summary)// <-- Beginning of callback function

…other stuff

From prior posts, it seems I cannot retrieve environment variables using the postman api using the newman library. Therefore I cannot use the jwt token in the environment.

So I export my environment json, which still doesn’t have the jwt token because we don’t want to save that as an initial value in the enviornment. To fix this I manually copy and pasted the jwt token into the environment json (“value” : “key”)

I try to run the collection and everything fails with the error:
getaddrinfo ENOTFOUND {{host}}{{version}}

I guess my first question is “Is this even the best way to do this?”
The second question being “Why doesn’t this work?”

-Thanks

P.S. How do I get the code snippet to format correctly? I push the </> button, then it puts this in the post
indent preformatted text by 4 spaces
Then when I paste my code, it doesn’t indent the code. Maybe the first line.
The only solution I’ve been able to figure out is that I have to go through my code example line by line and manually indent it. Any suggestions?

For the code render issue - Just copy the formatted code here and then add 3 backticks (```) to the line in front and the line after. :smile:

I’m about to head off but I’ve added a reminded to take a look at this and your other question when I get back online tomorrow.

1 Like

Test

require('dotenv').config();

const { Console } = require('console');

const newman = require('newman'); // require newman in your project

const key = process.env.postman_api_key;

// The signature for the run function is newman.run(options: object , callback: function) => run: EventEmitter

newman.run(

    {

        //collection: require('.\\Orders_1.postman_collection.json'),

        collection: 'https://api.getpostman.com/collections/13204628-74a6e824-c8d1-45fd-83e8-8a9003304b37?apikey=' + key,

        environment: require('.\\localHost.postman_environment.json'),

        //environment: 'https://api.getpostman.com/environments/12415606-e03e06c1-00f4-422a-891a-4e6984aa7cf3?apikey=' + key,

        reporters: 'htmlextra', // htmlextra is a reporting package for newman that will require installlation using NPM.

        reporter: 

        { //Go here for documentation: https://www.npmjs.com/package/newman-reporter-htmlextra

            htmlextra: //Report options

            {

                export: '.\\Results.html', //Directory and name

                template: '.\\InnovaAPITemplate.hbs', //Template used for report. Html, CSS and JS are all embedded.

                title: 'Innovations API',

                showEnviornmentData: true,

                browserTitle: "Innovations API",

                showMarkdownLinks: true,                

                showFolderDescription: true,

                //skipSensitiveData: true //Hides request header because it can contain the authorization tokens.               

            }

        }

    },// <-- End of options object

    function (err,summary)// <-- Beginning of callback function

    {

        if (err)

        { 

            console.log(err);

            throw err; 

        } else 

        {

            //console.log(summary);

        }

    }// <-- End of callback 

).on('start', function (err, args) { // <-- start event. 

        console.log('running a collection...');

}).on('done', function (err, summary) { // <-- done event.

    if (err || summary.error) {

        console.error('\nCollection run encountered an error.');

    }

    else {

        console.log('\nCollection run completed.');

    }

})

;

That is awesome! Thanks!

1 Like