How to automatically set new token's value as a dynamic variable and use this variable in my collection of requests?

Hello all,
The thing I’m trying to automate is setting a token as a dynamic variable to every next request after the login in my collection.
Because the token is different every time I log in, I’d like to know how this newly generated token can be automatically added to every next request. Is it a pre-request script in my collection, using collection variables or something else? Please let me know. Thanks in advance!

I’ll give you an example of my collection:
image
What I’d like to achieve is going through the requests using Runner and test if all the tests pass or not. Once executed the account should be deleted and new one created again in order to navigate through the same steps. That’s why I need to automate setting of the token.

You can use postman variables to store and use values ,

1 Like

@orbital-module-sagan Welcome to the Community :bouquet:

Yes as @praveendvd mentioned you can access the token by saving them in the variable depending on your scope.

Also if using OAuth2 toke, I suggest you to read this post

1 Like

@bpricilla @praveendvd Thanks for your help!
I’ve used environment variables and the following test in login request:

var jsonData = JSON.parse(responseBody);
var token = jsonData[‘access_token’];
pm.environment.set(“token”, jsonData.token);

…in order to achieve it.
Then for every next request I’ve used Bearer {{token}}.

I hope this will help other people who have the same issue like me.
Thanks a lot to the community!
See you on the next topic, bye.

Best regards,

2 Likes