-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Using Newman with the Postman API
This command stores the Postman API Key of the user. This key will be used to access Postman-Cloud resources in the future.
$ newman login
If an API Key is already stored, the command allows us to store the new API Key as an alias. Details regarding the usage of aliases are given later in this wiki. Internally, the API Key set initially is also stored under an alias named default
.
Newman stores all this information in the config file located in the Postman Config folder, ie ~/.postman/newmanrc
(in *nix-based systems) or C:\Users\$user\.postman\newmanrc
(in Windows systems).
If there is a need for project-specific aliases, this information can be copied to the .newmanrc
file in the project folder as well.
This command is used to delete a stored API Key. When more than one API Keys are available, it displays the aliases of all the API Keys and expects the user to select an alias to be deleted.
If POSTMAN_API_KEY
environment variable is not available, Newman uses the API Key stored under default
alias to communicate with Postman. If any other API Key needs to be used, the user can mention the alias of the API Key in the following ways.
The alias of the API Key to be used during the run can be set using the postman-api-key-alias
option as follows.
$ newman run $postman_collection_id --postman-api-key-alias=$alias
The alias to be used can be also be set using the POSTMAN_API_KEY_ALIAS
environment variable.
This medium turns out to be very useful in case one needs continuous access to remote resources using a particular key. A user can think of it as a session that keeps him/her logged-in with the corresponding profile until the shell is closed.
Following is the command to set the environment variable.
- In *nix-based systems
$ export POSTMAN_API_KEY_ALIAS=$alias
- In Windows systems
$ set POSTMAN_API_KEY_ALIAS=$alias
Note: One can check the current value of POSTMAN_API_KEY_ALIAS
as shown below.
- In *nix-based systems
$ echo $POSTMAN_API_KEY_ALIAS
- In Windows systems
$ echo %POSTMAN_API_KEY_ALIAS%