Set Environment Variables Programmatically in Postman
Abayomi Ogunnusi
Posted on August 30, 2022
Working with APIs, particularly those that use the JWT model for authentication, can be challenging because it requires copying and pasting the Bearer token into the Authorization headers.
The blog post explains how to reuse JSON web tokens in Postman, which will speed up your API Testing experience.
Prerequisite
Basic HTTP and RestAPI Understanding
Let's create an environment that allows us to change the context of our requests.
🎯 Select the Environment quick look option.
Click on the add button
🎯 Set the name of the Environment [green], the base URL, and click the save button
🎯 Change the Environment to the newly set one and also the baseUrl in two curly brackets
🎯 Hover over the baseUrl
to see the URL referenced from the environment variables.
🎯 Following that, we set our JWT
against the response token.
🎯 Try the request again, everything should still work
If you open the environment quick look section, the new JWT token should be listed as one of the variables.
🎯 To use the JWT on protected routes, follow the highlighted points.
Finally, if you open the headers tab, you will notice that the Authorization values are automatically prefilled.
Conclusion
I hope this post was useful and has shortened your API testing time. Thank you for reading.
Posted on August 30, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.