POSTMAN Collections are groups of pre-built requests that can be organized into folders so that, that the API requests can be run independently. Collection can also be shared with other collections. All the API requests can be stored and saved inside a collection.
Here, we shall see how to create a collection, create folders inside a collection and how to share a collection. Also, we shall see how to arrange requests inside a group.
To create a collection, open the dialog box by clicking the
As shown above, select the Collection and the collection window will open. Here, you can create your collection, by merely entering the collection name.
In my case, the name for my Collection is Collection02. In the Collection window, there are different tabs such as the- Description, Authorization, Pre-request Scripts, Tests and Variables.
Now click on the Create Collection Button to generate the collection. It will be an empty collection.
To create folders inside the collection, click on the collection name and a drop-down menu will appear below the collection name. Select the option called- Add Folder as shown below.
Once the Add Folder option is selected, you will be navigated to a pop-up window to enter the folder name. In my case, the folder name is folder02. Then click on the create button to create the folder.
To run the collection, we shall take the example of our earlier collection - Collection01, and the API request inside it.
Now, before we start to run the collection, we shall try to add some more requests inside the collection, so that, we can get a more comprehensive view of how a collection is run.
To add more API Request, we shall navigate the website(as we did earlier)- http://reqres.in. And search for a different API Request.
As you can see, this time we have selected the LIST USERS. And so the URL is copied along with the Request end-point of the Request -
/api/users?page=2, as shown in the picture. Now paste the same URL, into the URL bar of a new tab in your browser and check whether you get the response as below:
Now, as seen above, the response from the server is received successfully. Now, navigate to the NEW button in the POSTMAN again to open the dialog box and select Request. This is to create a new Request.
Now, create a new folder named GET, inside the Collection - Collection01 and drag and drop the two create requests- GET Response and GET_user_list into the build folder. This is done just to arrange things in a proper way.
Now, navigate to the collection tab and select the collection you want to run. For, my case it is- Collection01.
Now, you may open the collection folder to see what are the requests inside it. Then select the right arrow on the right side of the collection name, and you should be able to see the RUN button.
The RUN button will appear once you hit the arrow on the collection.
Then the next confirmation window will pop up. Select the Run Collection button, and you are ready to go.
Once, you hit the button- Run Collection01, you should be able to see the below window:
As you can see from the output above, the Collection Runner has popped up in a new window, and all the results are inside the window.
The Result window consists of the Request Name, the link visited, the status of the response (which is 200 here, means OK), the time required to get the response (in mili-seconds). And the size of the response data.
In this section, we shall see how we can get data from a CSV file And a JSON file. A CSV file is a file which contains all the values separated by a comma(
,). And so the CSV is the acronym for comma-separated values.
First, create global variables that can be substituted in the request URL and in the body. To create global variables first go to the manage environment icon on the top-right corner on the homepage of the POSTMAN software. And then, go to globals and input the variables.
Then, go to Globals:
Now, enter the variable names and enter the corresponding values. I have named my variables as- endpoint, email, and password.
Now, go back to the request page and then replace the endpoint values with the variable name in the URL bar. And also replace the values in the body with the appropriate variable name.
Now, save and send the request and see whether the request is generating the same response.
Now, you have seen that variables can be used in request URL as well as in the body.
Now, we shall see how to get the same values from a CSV file. That is we shall create a CSV(Comma Separated Value) file and will have some values like: end-point, email and password.
Now, just go to any folder or location of your computer and create a file called
Now, save the file in any location you want and reopen in any text editor and just put a (,) after all the values inside. This is done to indicate a CSV(comma-separated value) file. In case, not separated by a comma, there can be a format related error at the time of running the collection.
I have used notepad++ software to open the file and edit it.
Now, to the collection runner and address the CSV file there:
Now, run the collection by clicking the Run Collection button on the same page.
Now, the response, along with all the details can also be exported into any folder you want. Just click on the export button on the top-right corner of the collection runner page and export the file.
Now, the location, you selected at the time of saving, check on that location for your exported file.
Similarly, the way to import data from a
json file is also the same. Just write the script in a text file, save as a
json file, and address the file in the collection runner.
This is how a
json file looks like. There are three values- endpoint, email and password.
Now, select your file in the Collection runner window:
The report file can be exported in a similar way as we did.
To run a POSTMAN Collection remotely, just go to the collection you want to run and select the triple-dot button right to the collection name. In the options, you will get share button.
Click into the button and you must see a window popping out. Select the Getlink button from there.
Now, copy the link and go to your command prompt.
newman run your_copied_link. And hit enter.
C:UsersHP>newman run https://www.getpostman.com/collections/664090bd3c82e2ecb4d5 newman: Newman v4 deprecates support for the v1 collection format Use the Postman Native app to export collections in the v2 format newman collection-test01 → new01 POST https://email@example.com [201 Created, 690B, 1740ms] ┌─────────────────────────┬─────────────────────┬─────────────────────┐ │ │ executed │ failed │ ├─────────────────────────┼─────────────────────┼─────────────────────┤ │ iterations │ 1 │ 0 │ ├─────────────────────────┼─────────────────────┼─────────────────────┤ │ requests │ 1 │ 0 │ ├─────────────────────────┼─────────────────────┼─────────────────────┤ │ test-scripts │ 1 │ 0 │ ├─────────────────────────┼─────────────────────┼─────────────────────┤ │ prerequest-scripts │ 1 │ 0 │ ├─────────────────────────┼─────────────────────┼─────────────────────┤ │ assertions │ 0 │ 0 │ ├─────────────────────────┴─────────────────────┴─────────────────────┤ │ total run duration: 2.2s │ ├─────────────────────────────────────────────────────────────────────┤ │ total data received: 100B (approx) │ ├─────────────────────────────────────────────────────────────────────┤ │ average response time: 1740ms [min: 1740ms, max: 1740ms, s.d.: 0µs] │ └─────────────────────────────────────────────────────────────────────┘
As shown above, all the details are displayed in the command line itself.
There can be multiple requests in one collection of POSTMAN. This is one of the benefits of using collection. There are cases and situations where we may require to send multiple requests and get back the response. So let us see, how this can be done using the collection.
First of all, we shall create multiple requests inside a collection. In my case, I shall create two requests inside a single collection.
We shall name the collection name as- collection-testing.
And the first request name is-
list-all-user, and the second request name is
Open the POSTMAN software, and go to create New collection.
Then click into the Collection option and create a collection-
And click on
After creating the collection, navigate into the collection and then create two different requests.
First, create the first request-
Save the request into the collection-
Enter the URL https://reqres.in/api/users?page=2 into the Request URL bar and save the request.
Then create the next request-
list single user.
And save this request into the same
Enter the URL https://reqres.in/api/users/2 into the Request URL bar and save the request.
Now, when both the request is saved. Just Click into the Send button and confirm whether both the requests are executing well. You can also add a code snippet from the POSTMAN itself to check whether the status code is 200.
Now, go to your collection and click into the arrow and then click into the Run button, which will open the collection runner.
Then the collection runner window will pop up, click into the Run Collection button.
Below you can see that both the collections- list-all-user and list-single-user get executed.