Hello everyone! Postman is one of the most popular API testing tools - it combines the ability to test things manually and add some sort of automation to it. In this article you’ll know how to best organize your Workspace in Postman - it’ll help you faster reach any request your need and get rid of some manual tasks like renewing your authorization token. So let’s begin with the creation of a new Workspace! Environment Usually, there are at least a few environments in most of the projects - (where developers upload their features first and might test them on their end), (platform for QA verification) and , of couse. development staging production Every environment has a bit different base url, but path (route) usually stays the same. For example: - production https://example.com/some/route - https:// .example.com/some/route staging staging - https:// .example.com/some/route development dev See? In case of and environments - they simple have subdomains assigned, but the path (some/route) stays the same. It means that base url is one of our first candidates to become an - a value that changes between environments. staging development environment variable Usage of base url as an environment variable let us use a single template in Postman to send a request to any environment that we have configured in our collection. Now let’s create a new Environment and name it . These are the variables that we’re going to add: Production baseUrl value - https://paysis.herokuapp.com base url of test application that we’ll use in current article token authorization token - it’ll be updated dynamically, so it must be empty for now login value - adminius login for auth request password value - supers3cret password for auth request And don’t forget to click button to save our current progress with the environment. Save Production Collection Now it’s time to create a Collection to organize our templates - it is as simple as our previous step with environment variables. Let’s name new collection and select as an since this is the one that current application use. Below, in section, enter environment variable (don’t forget to put parentheses as well - that’s how you address to environment variables in Postman). After that select the Environment that we created in our previous step. Paysis Bearer Token Authorization Type Token baseUrl Once again, don’t forget to Save current collection - either press ( ) / ( ) or click (three dots) button. Control + S Windows / Linux Command + S MacOS View more actions Our Authorization config will be applied for every request in the current Collection automatically. Authorization Let’s create our first request - this one is going to be an authorization request which makes our further testing possible (since we need an authorization token to send other requests as an authorized user). To create a new request template - simply click right mouse button on your Collection name in list and select . Let’s name this one . Add Request Auth It is a request to endpoint with body: POST /auth JSON { "login": "{{login}}", "password": "{{password}}" } , and are environment variables there that are taken from environment that we’ve created earlier. baseUrl login password Production There’s one thing that we’d want to automate here - update environment variable with a value from this request’s response, so we can reuse this value in other requests that must be executed under authorized user. To do that, let’s go to tab in current request and paste this code there: token Tests var responseData = JSON.parse(responseBody); postman.setEnvironmentVariable("token", responseData.token); This section is there for small automated tests and scripts (just like the one that we already implemented). It accepts only. Once you’ll send a request - code from this section will be executed. JavaScript By the way, since this request doesn’t require any authentication header - we must remove it (because it was automatically applied by collection). To do that - simply go to tab of current request and select No Auth in the dropdown. Authorization Now it’s safe to execute our first request in the collection - hit button. Send Once you’ve done that - you’ll see authorization token from response in your current environment. This variable with your token will be included by default in your future requests of the current collection. Auth Functional Separation of Requests After some time you’ll see that your collection is growing and it’s hard to find a request that you need in this mess. It’s better to separate requests by groups (sub-collections of collections) right from the start. For , we have request in the root of the collection. For other logic ( , , ) there are sub-collections. Paysis Auth Users Transactions Config Don’t forget about proper naming of requests so other people could find whatever they need as well. Summary So here’s what you need for the best experience with : Postman Use in your workspace to adapt your requests to various environment. environment variables Add that automate data transitions between requests (like sharing authorization token from request into all other requests). scripts Auth Create and . sub-collections name your requests properly Thanks for reading, I hope you’ve learned something new!