Postman Tip

Thilina Dilshan
3 min readOct 18, 2021

In this article I am going to give you a quick tip of postman that can help you when you are working with token with postman.

when you are doing postman check it is common case that you have to check the authentication routes. So when you get token from sign in route you have to add that token to all other request as authorization header to check the routes of your application.

It can be really annoying if you have to add that header to all your routes manually by copy and pasting. But postman cover it for us.

First you have to call your sign in route and get the token with your request.

You can get your token. (Please consider this is a dummy response. password should be hash and should not be in the response)

Then you can do some work to make that token store in the every request that you send from the postman.

  1. Create a environment and variable for that token

Go and Add environment and then set a variable name and set this environment to your collection like this. In my case environment is test and variable is authToken and I set this test environment to my collection. You can see it in below.

Ok now the first step is over. Then we can go to the second step.

2. Add that authToken variable to your collections Token Bearer Token like below.

First go to three dots and you can see the Edit option. Click Edit and you can see the below screen and set Bearer Token and give the name of the variable you set. In my case authToken. Set it inside two curly braces like below.

3. In every request set your Authorization type to Inherit from parent (It is the default one)

4. Finally write this simple code in your sign-in request Tests section in postman.

This is it. Then from every request this token is automatically added to your authorization header by postman as Bearer Token.

if(pm.response.code == 200){

pm.environment.set(‘authToken’, pm.response.json().token)

}

Please consider in my sign-in response I get the token as token that’s why pm.response.json().token.

So now you don’t worry to copy paste this token for every request that you going to test by postman.

I think this tip help you to reduce lot of copy paste pain. Thanks for the reading. Will meet agin with the nice tip. Until then stay safe. Bye.

--

--