When testing some API, the token need to be generated each 3min and I would like to do the refresh automatically, I did the following
I have a collection CollectionGetter
which contain some requests
CollectionGetter
collection :I've added the following script in "Tests" tab
var jsonData = pm.response.json();
pm.environment.set('getToken', jsonData.access_token);
on authorisation tab, set:
Type = Bearer token
Token {{getToken}}
then selected a request under CollectionGetter
:
getAccount (GET url/api/account)
Auth = inherit autho from parent
and sent it
=> got a 401 JSONError: No data, empty input at 1:1
Any help? Is my configuration correct?
Postman now has a feature that auto refresh auth tokens, you just need to setup authentication at the collection level and togle "the auto refresh access token" option: Image showing the auto refresh access token button
here's postman walktrough video about that feature, worth a watch: https://www.youtube.com/watch?v=FAhs9TBK-xU
TLDW:
1 - Click on your collection, it'll open the "auth" tab.
2 - Configure you Authentication type with Oauth 2.0
3 - Scroll to the bottom of the page and set your credentials and click "get new access token"
4 - Go up and togle the "Auto-refresh access token" option: Auto-refresh access token option
5 - With your token already generated go to your request, open the authorization tab of the request and set "type" to "inherit auth from parent", everything should work just fine.
Aditional resource: postman blog post about the feature
*for testinging local in postman , Best method to set bearer token for all the request quick and easy way is, first you create a bearertoken with validity for more than 1 year(so it will not ask expired ) and copy ,and click on the postman collection top of the folder , if collection is
commonapi>1)loginapi >2)signupapi >3)homescreenapi
, like this format , click on top folder name commonapi, and there you can set bearertoken and paste the value , now in loginapi and all the below subfolder apis we can just set inherit auth from parent , so we dont need to create and set everytime bearer token again and again ,and it will save more time.*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With