Introduction
Postman CLI – It is a command line interface which is used to run a postman collection The use of postman CLI starts with the installation of the Postman In this topic we will see the installation, the different features and how to use Postman CLI.. The Postman CLI enable us to perform the following operations
- Run a collection with its collection ID or path.
- Send run results to Postman by default.
- Supports sign in and sign out.
- Check API definitions against configured API Governance and API Security rules
Postman CLI Usage
The following Postman CLI commands make calls to the Postman API and count toward your Postman API usage:
postman login
– Uses one call to authenticate a user with a Postman API key.postman collection run
– Uses one call to fetch a collection by ID, one call to fetch an environment (if any), and one call to send data back to Postman.
Postman CLI Installation
The installation of the Postman CLI will be made for different type of operating system. The installation of the Postman CLI differ as per the operation system
Windows
powershell.exe -NoProfile -InputFormat None -ExecutionPolicy AllSigned -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://dl-cli.pstmn.io/install/win64.ps1'))"
Mac
curl -o- "https://dl-cli.pstmn.io/install/osx_arm64.sh" | sh
Figure 1.0 : – Postman installation
Postman Command Options
This topic is mainly used to discuss postman basic commands. In this section. , the basic commands will be discussed one by one and learn how to use the postman command
Version
One the postman is installed, checking the postman version is the first option.
postman -v / postman --verion
Figure 1.1 : – Postman Version
Help
To get the most help for the postman CLI, make sure to apply the following command
postman --help / postman -h
Figure 1.2 : – Postman Help
Postman login
This command authenticates the user and locally caches the Postman API key. login
requires one option, --with-api-key
, that accepts the Postman API key. The login
command is required only once per session. Once you’ve signed in, you remain signed in until you use the logout
command or your Postman API key expires.
postman login --with-api-key <api-key>
Figure 1.3 : – Postman Login through API
Postman logout
This command signs you out of Postman and deletes the stored API key.
postman logout
Figure 1.4 : – Postman Logout
Running Collection
This is a command used to run a collection and sends all run results and responses to Postman servers. You can specify the collection with its file path or Collection ID.
// Running only collection using Json
postman collection run /myCollectionFolderName/myCollectionFile.json
// Running only collection using collection ID
postman collection run 12345678-12345ab-1234-1ab2-1ab2-ab1234112a12
// Running collection along with environment ID
postman collection run 12345678-12345ab-1234-1ab2-1ab2-ab1234112a12 e 23461356-1ba80dcb-2bdd-4ced-8a2f-07a4fa00affa
Figure 1.5 : – Postman using Json / collection ID