0
0
Postmantesting~5 mins

Running collections via CLI in Postman

Choose your learning style9 modes available
Introduction

Running collections via CLI lets you test your APIs automatically from the command line. It helps you check your API without opening the Postman app.

You want to run API tests automatically after code changes.
You need to run tests on a server or in a continuous integration system.
You want to share test runs with your team using scripts.
You want to run tests without using the Postman graphical interface.
Syntax
Postman
newman run <collection-file.json> [options]

newman is the command line tool to run Postman collections.

You must have Node.js and Newman installed to use this command.

Examples
Runs the collection file named mycollection.json with default settings.
Postman
newman run mycollection.json
Runs the collection using a specific environment file environment.json.
Postman
newman run mycollection.json -e environment.json
Runs the collection and outputs results in the console and saves a JSON report to result.json.
Postman
newman run mycollection.json --reporters cli,json --reporter-json-export result.json
Sample Program

This command runs a collection from a URL using your Postman API key and shows results in the command line.

Postman
newman run https://api.getpostman.com/collections/12345678-1234-1234-1234-123456789abc?apikey=your_api_key --reporters cli
OutputSuccess
Important Notes

Make sure you have installed Newman by running npm install -g newman.

You can run collections from local files or URLs.

Use environment files to test APIs with different settings easily.

Summary

Newman lets you run Postman collections from the command line.

You can add options like environment files and reporters for better control.

This helps automate API testing outside the Postman app.