How to run postman Collection and Environment in CMD using newman by using Postman APIKey

508 Views Asked by At

I want to run my postman Collection and Environment in CMD using newman by using Postman-APIKey.

What I tried:

newman run "https://api.getpostman.com/collections/{{collectionKEy}}?apikey={{APIKey}}&EnvironmentKey={{EnvironmentKey}}"

After running, I get the following error for every requests which using environment variables:

"runtime:extensions~request: request url is empty"

Or is there any other way to use both Environment and Collection?

2

There are 2 best solutions below

0
On BEST ANSWER

It appears that your newman command is incorrect, the correct syntax to run a collection with an environment would be:

newman run https://api.getpostman.com/collections/$uid?apikey=$apiKey -e https://api.getpostman.com/environments/$uid?apikey=$apiKey

Full details and all the cli commands can be found on the Newman repo:

https://github.com/postmanlabs/newman

1
On

you can also run a Postman collection and environment using Newman in the command line after creating configuration json file.

you can create a file named postman-config.json:

 {
  "collection": "https://api.getpostman.com/collections/{{collectionKey}}",
  "environment": {
    "url": "https://api.getpostman.com/environments/{{environmentKey}}",
    "apikey": "{{APIKey}}"
  },
  "globals": {},
  "iterationData": [],
  "exportEnvironment": "postman_environment.json",
  "exportGlobals": "postman_globals.json",
  "exportCollection": "postman_collection.json",
  "exportFolder": "./"
}

Navigate to the directory where the postman-config.json file and run the following command to execute the collection using Newman:

sh Copy code newman run postman-config.json