Creating Collection in POSTMAN

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.

Benefits of using Collections in POSTMAN:
  • Collection can help you share the created API requests with different other collections.
  • A collection can be imported or exported, thus can save time for transferring the requests.
  • An environment can be applied to a collection easily.
  • Setting any variable for collections will automatically apply the same into the folders and requests create under the collection.

To create a collection, open the dialog box by clicking the New button and select Collections.

postman-collection-window

As shown above, select the Collection and the collection window will open. Here, you can create your collection, by merely entering the collection name.

postman-collection-creation

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.

postman-collection-created

Adding folders into the 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.

postman-collection-add-folders

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.

Not only one folder but many folders can be created inside a collection.

Running Collection in POSTMAN

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.

postman-another-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:

postman-second-response

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.

postman-collection-tab

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.

postman-collection-arrow

The RUN button will appear once you hit the arrow on the collection.

postman-run-button

Then the next confirmation window will pop up. Select the Run Collection button, and you are ready to go.

postman-run-collection

Once, you hit the button- Run Collection01, you should be able to see the below window:

postman-collection-run-output

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.

Getting data from CSV and JSON Files in Collection

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.

postman-manage-environment

Then, go to Globals:

postman-create-global-variables

Now, enter the variable names and enter the corresponding values. I have named my variables as- endpoint, email, and password.

postman-global-variables-edit

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.

postman-variable-replacement-done

Now, save and send the request and see whether the request is generating the same response.

postman-same-response-after-variables

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 data01.csv

postman-csv-file

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.

postman-csv-values

Now, to the collection runner and address the CSV file there:

postman-collection-runner-select-file

Now, run the collection by clicking the Run Collection button on the same page.

postman-collection-run-request-body

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.

postman-export-result

Now, the location, you selected at the time of saving, check on that location for your exported file.

postman-collection-file-export

postman-exported-file-demo

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.

postman-json-file

Now, select your file in the Collection runner window:

postman-json-file-upload

postman-collection-run-request-body



The report file can be exported in a similar way as we did.

Running POSTMAN Collection Remotely

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.

postman-collection-share

Click into the button and you must see a window popping out. Select the Getlink button from there.

postman-getlink-option-copy

Now, copy the link and go to your command prompt.

Now, type: newman run your_copied_link. And hit enter.

Output :

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://reqres.in/api/users?page=2&email=eve.holt@reqres.in [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.

Multiple Request in one Collection

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 list-single-user.

Open the POSTMAN software, and go to create New collection.

postman-new-collection

Then click into the Collection option and create a collection- collection-testing.

postman-collection-naming

And click on Create to create the collection.

postman-collection-create-button

After creating the collection, navigate into the collection and then create two different requests.

First, create the first request- list-all-user.

Save the request into the collection- collection-testing.

Enter the URL https://reqres.in/api/users?page=2 into the Request URL bar and save the request.

postman-list-all-user-request

Then create the next request- list single user.

And save this request into the same collection-testing.

Enter the URL https://reqres.in/api/users/2 into the Request URL bar and save the request.

postman-list-single-user

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.

postman-collection-run-button

Then the collection runner window will pop up, click into the Run Collection button.

postman-collection-share-button-last

Below you can see that both the collections- list-all-user and list-single-user get executed.

postman-two-collection-run

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions