1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ghasem Tabatabaei
  • 145
  • 1
  • 1
  • 12
  • If you're seeing that error, it's running the collection. Are the URLs a variable? Are those saved in the initial value? – Danny Dainton Aug 07 '23 at 10:11
  • @DannyDainton I have some base variables (eg. BaseUrl, ...) which they are stored as variable in Environment, and also some variables in collection. In addition, any variable has "Initial value" and "Current value" assigned (same value). – Ghasem Tabatabaei Aug 07 '23 at 10:22
  • Just realised that in your command, you're not using the `-e ` you have added environment key as a param on the collections URL. For example - `newman run -e ` – Danny Dainton Aug 07 '23 at 10:49

2 Answers2

1

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

Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
0

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
  • Thanks for your answer. I would like to use APIKEY, collection-id and environment-id but not exporting them. I found a solution the same you mentioned, but using APIKEY and fetch both Collection and Environment. – Ghasem Tabatabaei Aug 14 '23 at 15:04