Skip to content

Using Newman with the Postman API

Udit Vasu edited this page Sep 1, 2020 · 1 revision

Table of contents

  1. newman-login
  2. newman-logout
  3. Postman API-Key Alias
    1. Command Option
    2. Environment Variable

newman login

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.

newman logout

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.

Postman API Key Alias

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.

Command Option

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

Environment Variable

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.

  1. In *nix-based systems
    $ export POSTMAN_API_KEY_ALIAS=$alias
  2. In Windows systems
    $ set POSTMAN_API_KEY_ALIAS=$alias

Note: One can check the current value of POSTMAN_API_KEY_ALIAS as shown below.

  1. In *nix-based systems
    $ echo $POSTMAN_API_KEY_ALIAS
  2. In Windows systems
    $ echo %POSTMAN_API_KEY_ALIAS%