Collections in Postman
Till now, we have learnt the terminologies of Postman in-depth and also have made some GET Requests. In the previous tutorials, we mentioned and briefly explained collections. Recall that Collections are a group of requests grouped into one folder. So that we can use them and share them easily. But in this tutorial, we will learn that a Collection is much more than that.
The definition of Collections is confined to a just grouping of requests. But, grouping of requests can have unparalleled advantages and make the work of a software developer many folds easy. We will now learn how to step by step save a Collection.
How to create and save collections in Postman?
1.First of all, hit the endpoint http://restapi.demoqa.com/utilities/weatherfull/city/Hyderabad and in the response box change the format to Text to see the result.
2. Now go to Collections Tab and press the icon that says, New Collection.
3. Write a name of your choice for your first collection and it’s description. In the following image you can see I chose the name MyFirstCollection and a simple description.
4. Press Create to create your first collection.
5. Now, you have your first collection created but it’s empty as of now. Press Save button in the side of address bar.
6. Choose your collection name in the panel as shown in the image. Press Save.
Now look at the collections tab, you will have the request saved below your collection name.
You can click on the Meatballs menu in the side of the collection name and you will see some options. We will talk about the following options in this tutorial.
- Share Collection
- Export Collection
- Add Folder to a Collection
- Duplicate the Collection
- Remove the collection from workspace
- Delete the collection
- Leave a comment on the collection
Share collection option is used to share the collection to other people such as your team members.
Sharing a collection is very important when you are working in a company or in a team. There are times when developers create a bunch of Postman Requests while developing APIs to test it. You can request developers to share their collections and you get benefits of it. Or even you create a bunch of Postman Requests, save it to a Collections and share it with your team. It is not worth sharing every request one by one. Rather, we share our Collection as a whole to the team members or anyone to whom we want to share through different methods listed below.
For example, if you are a tester and find out some bug, you can save your steps to reproduce in a Collection, and attach the same to the bug for the developer as a proof and to reproduce the issue. For using this option you must be signed into postman. After signing into Postman you get two options to share the collection.
- Through workspace
- Sharing through link
A workspace is a collaborative environment for a group of users to develop and test APIs. In simpler terms, workspace is the project in which you work. A setting done in a workspace remains in the same workspace. It is like a shell in which you work. There has to be a workspace to work in Postman, you cannot work isolated. There are two types of workspaces inside Postman
- Team Workspace : To use the option of Team workspace your company or you must have purchased the Postman Pro version or else this feature won’t work. In Team workspace option, your team can test api simultaneously on one workspace and anyone can edit and update (with permissions). This comes handy when teams are located in different locations or different buildings also. Once edited, everyone’s api is updated automatically. There can be any number of Team workspaces.
- Personal Workspace : A personal workspace is similar to the team workspace but the difference being this workspace is completely personal to the user who created it. Postman will have no contribution in updating it at any machine, if present.Collections present in the personal workspace is shared through link which is detailed below.
Individuals can organize their work in personal workspaces and teams can collaborate in team workspaces. When you start Postman, you are already inside personal workspace as shown.
You can create unlimited personal workspace which will be personal to your machine and can test any number of API.
Share Collection through a link
Second option is by creating a link and sending it to the people of your team. This link will be of Postman Cloud. So, your collection will be first uploaded to Postman cloud and then anyone can access it through that link. But, this feature is not recommended while working in a company sometimes because the Apis are personal and companies would not want them to be in other cloud which is not safe.
Export Collections in Postman
Export feature is used to export the collection as a whole by saving it to your computer and which can be later share with the team over the Email in a zip file. Or it can also be shared over a network sharing.
Follow these steps to learn about exporting the collection.
1.Click on export as shown in the above image.
2.You will see two or three options (depending on your version of Postman). For this tutorial we are using Postman ver 6.0.10. We will choose the option Collection v2.1 and press Export.
This will open the box to save the collection in the Json format on your computer wherever you want. Then this json file can be shared with your teammates by any means just like a file.
Collections also let you make folders inside your collection and then save the requests inside your folders. This can further help you to sub-categorize the requests. For example, in the previous chapters we took the example of movies folder to explain collection where you can store all your movies. Making a folder is like making another folder inside Movies folder, such as “English Movies” which will contain all the english language movies, but they are still movies. Similarly, here we can make folders inside the collection and store our requests.
1.Choose the option Add Folder.
2. Name your folder and press Create.
Now you have your folder created but as of now it is empty.
3.Drag the request and drop it on the folder name.
This will move your request to your folder and you are all set.
The option Duplicate as the name suggests, duplicates the collection into a new collection. It means when you click on Duplicate, you make another copy of the same collection in the workspace.
1.Click on Duplicate.
2.You can see the copy in the sidebar underneath the original collection.
Remove From Workspace
Remove from workspace option deletes the collection from the workspace that you are working on.
If it is a personal workspace then you can delete it by choosing the option whereas if it is a team workspace then you need to have permission for deleting any collection or request from the workspace.
Delete and remove from workspace option might seem similar but they differ in just one aspect. Remove from workspace deletes the collection from the current workspace but delete option will delete the collection or request from all the workspaces wherever it is present. Needless to say, you need permissions for this.
Leaving a comment on the collections in Postman
It is quite obvious that when we work in teams, our workspace faces a lot of edit. This can be anything from editing a simple request to editing one test in that request. Now, since you need to apprise everyone what you did, Postman brings you the comment feature. Through this feature you can leave comments in the collection so that everyone can know what you just uploaded in a chronological order.
For this press the arrow button beside the collection name
Select View in Web from the options
This will open the collection in your browser. This can be seen by everyone working in the same workspace. Select comments on this page.
This will show you the popup to enter the comments.
We will learn in the next section how to import collection in Postman.
How to Import Collections in Postman
If we can export our collection then needless to say it must be imported in some other Postman. So, like export we have another option import but that does not reside inside the meatball menu. The import collection is a part of header as shown below.
Importing a collection is easy in Postman. When you click on import you will see the import panel in front of you.
Here, as you can see there are different methods that can be used to import a collection. These methods are
- Importing through drag and drop method
- Importing the folder
- Importing through link
- Pasting the raw text
Importing through drag and drop
Importing through drag and drop is pretty simple. It works the same as the upload feature in many websites such as Google Drive. If you have a collection file in you system just click on that file and drag it to this panel and release the mouse (or drop the file). This way the file/collection will be automatically uploaded in your Postman.
Importing the folder
Importing the folder is same as the previous option just the difference being, in the previous one we were uploading single collection but in this one we can upload multiple collections all at once. Just make a folder inside your system and paste or export many collections in it. When you import the same folder in your Postman, you will see all the Collections being uploaded. If you already have any of the collection from that folder, you will be asked to replace it or form a copy of it.
Importing through link
As we discussed in the previous tutorials, when we work in teams, we often use the Postman cloud or Team workspace which provide us the link to the collection so that everyone can use it without any problem. So importing through link is the same feature. We can provide link of the same collection in the box and the collection will be imported.
Pasting the raw text
In the above image, the first line in the panel tells us what files can be imported in Postman. There are many files apart from collection like curl or RAML etc. These files can be imported through raw text coding like in curl file. Although this feature is out of the scope of this course, therefore we won’t be discussing it in detail.
You might wonder about the collection runner which we introduced earlier which is used to run the collection requests all at once. We will talk about it after concluding “Tests” topic. It will make more sense in the next tutorial.
Since we have come so far in Postman, it would be better if you try out some scenarios yourself.
- Create a collection named PracticeExercises
- Create a folder inside the collection and name it Post Requests
- Inside the folder save the request which was used in the last chapter (POST Request) only after getting correct response.
- Save the collection inside your computer as a JSON file.