Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authorization bearer token in postman

Im trying to automate postman tests with Newman. There is an issue with authorization. The authorization bearer token changes and it is dynamic. Does anyone know how to automate this?

like image 702
Zed Avatar asked Feb 13 '26 14:02

Zed


1 Answers

Postman has this nice feature of variables. You can read more about them here: https://www.getpostman.com/docs/v6/postman/environments_and_globals/variables

You can store the bearer token in a variable and update it periodically as per your requirement.

Using global variable

You can modify this token in the pre-request script / tests script as per your needs.

For eg:

let token = pm.globals.get('dynamic_token');
token = 'newModifiedToken90332'; // Perform some operations here.. 

pm.globals.set('dynamic_token', token);

Pre-request script

You can export the collection and globals into Newman and use them.

From Newman documentation you could do the following:

$ newman run mycollection.json -e dev_environment.json

-e is for using environment variables in which you can store your bearer token Recall that you can export your collection and your environment variables as well.

like image 154
Sivcan Singh Avatar answered Feb 17 '26 20:02

Sivcan Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!