How to automatically set a Bearer Token for your Postman requests?

Hi @d.rajkhowa02

You can do in other way also .Set a environment variable with the name Token . Below are the script you can write down inside Test tab.

var res = JSON.parse(responseBody);
if(data.KeyName === ‘Your API KEY Name’)
{
pm.environment.set(“Your variable name”, res.token);
}

it will save the token value inside the variable what you declared in environment .

For this you have to make a csv file with two field Key name and Keyvalue .that can be passed with the help of post man runner,select your environment there .

Defiantly it ll work .I have done in the same way.

3 Likes