Running a collection lets you test many API requests automatically in one go. It saves time and helps find problems fast.
0
0
Running a collection in Postman
Introduction
You want to test all API endpoints of your app at once.
You need to check if your API works after making changes.
You want to run the same tests every day to catch bugs early.
You want to share your tests with teammates easily.
You want to see a report of all test results together.
Syntax
Postman
pm.collection.run(collectionId, options, callback);
collectionId is the ID or name of the collection you want to run.
options can include environment variables or data files for the run.
Examples
Runs the collection named 'My API Tests' with default settings.
Postman
pm.collection.run('My API Tests');Runs the 'User API' collection using the 'Dev Env' environment variables.
Postman
pm.collection.run('User API', { environment: 'Dev Env' });
Runs 'Order API' collection with data from 'orders.json' and logs when done.
Postman
pm.collection.run('Order API', { data: 'orders.json' }, function(err, summary) { console.log('Run complete'); });
Sample Program
This script runs the 'Sample Collection' using the 'Testing Env' environment. It prints the total and failed requests after the run.
Postman
const collectionId = 'Sample Collection'; const options = { environment: 'Testing Env' }; pm.collection.run(collectionId, options, function(err, summary) { if (err) { console.log('Error running collection:', err); } else { console.log('Collection run complete.'); console.log('Total requests:', summary.run.stats.requests.total); console.log('Failed requests:', summary.run.stats.requests.failed); } });
OutputSuccess
Important Notes
Make sure the collection and environment names are correct.
You can run collections manually in Postman or automate with Newman CLI.
Check the summary object for detailed test results after running.
Summary
Running a collection tests many API requests automatically.
Use options to set environment or data for the run.
Check the run summary to see how many tests passed or failed.