Developers are a special breed. We never stop studying or programming, including outside of work. It comes with the job–just like sharks can never stop swimming, developers can never stop learning. When I come across some new tips and tricks on how to better use some of my favorite (and arguably, most important) tools, I jump at the chance to learn. And that’s why I want to share some amazing Postman tips for API testing with you in this Postman Guru series!
In my last post, we went over the benefits of working with the Postman API testing application, and I covered four tips to help get you started with your Postman learning goals. In today’s post, I’ll continue with four additional tips that will help you streamline your work and become a Postman master. If you missed the first post in this series, be sure to go back and check it out for additional tips and tricks.
For now, let’s swim on with another round of tips!
Rounding Up Four More Postman Tips and Tricks for API Testing
First Tip: Utilize the Postman Console to update environment variables with data from a JSON response
A great tip I recently learned utilizes the Postman console to update environment variables with data from a JSON response. You can write a quick script (example below) that will parse the JSON response returned after making a request, then update an environment variable with this response data – all within Postman.
I use this trick when getting a session key. There are many requests in the DataMotion Postman collection that require a session key, so I first made a ‘SessionKey’ variable that allows me to easily update each instance at one time (I go over how to create a variable in my previous post). Then I added the below code to my console, where I am capturing an updated session key from DataMotion’s ‘Get Sessionkey’ API call and populating the ‘SessionKey’ variable with the response.
var data = JSON.parse(responseBody);
Now the ‘SessionKey’ variable within most of my requests will always reflect the most updated session key received with the ‘GetSessionkey’ API call.
Second Tip: Utilize Postman’s find and replace feature
We figured out how to create and update variable values very easily, but what about the variable name? As I said before, the session key variable is scattered across the DataMotion collection. If the variable name needed to change or be updated, it would be a long and menial task to complete. However, this work can be replaced with Postman’s find and replace feature.
To rename a variable, such as the session key variable or an attribute name, navigate to the bottom right of your Postman window to find the “Find and Replace” button. Select this button and type in the phrase or regex pattern you would like to identify. From here, select specific instances of this phrase that you would like to update, or select all. Then enter the new phrase you would like to replace these instances with under the “Replace With” section and hit “Replace”.
Voila! Your variable names have been updated.
Third Tip: Select the code icon on the right panel to get a code snippet of the request
We learned in the last post of this tip series that Postman is an API testing tool, so it’s great for testing out your API calls. But did you know it can help turn these requests into code, too? Once your Postman request is configured, you can select the code icon on the right panel, select a programming language, and copy a code snippet of the request.
From here, you can go ahead and add this snippet in your projects for easy development!
Fourth Tip: Create documentation for your collections with the documentation icon on the right panel
The magic doesn’t stop there. As a final tip, you can create API documentation for your Postman collections with the documentation icon on the right panel as well.
Once you have selected the documentation icon, you will see documentation for your request that includes details on the endpoint, parameters, headers and body values. You can also select ‘View the complete documentation’ button at the bottom of this view to get documentation on your entire collection. From here, you can select publish in the top right corner to publish this information, directly from Postman.
More Tips Are on The Way!
It’s official: you are that much closer to becoming a Postman guru! I would recommend trying these tips out on a test collection, or a collection you’re very familiar with, before implementing these new skills in your everyday workflow. Once these skills are implemented, you will be flying through your Postman tasks.
I’ll be back with more tips and tricks on your favorite programming tools soon–the next series will be posted on our Twitter, Facebook, and LinkedIn pages every Tuesday. Be sure to check them out!
To test DataMotion secure message center APIs, you can download our Postman collections on GitHub. To find out more on how our secure message center APIs can help you, visit datamotion.com.