I\'m trying to send an authenticated request with one click in postman.
So, I have request named \"Oauth\" and I\'m using Tests to store the token in a local variable.>
NOTE: There now is a way to do this in a pre-request script, see the other answers. I'll keep this answer for posterity but just so everyone knows :)
I don't think there's a way to do this in the pre-request script just yet, but you can get it down to just a few clicks if you use a variable and the Tests tab. There are fuller instructions on the Postman blog, but the gist of it is:
In the Tests section of that request, store the result of that request in a variable, possibly something like the following:
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", data.token);
Run the authentication request -- you should now see that token
is set for that environment (click on the eye-shaped icon in the top right).
{{token}}
wherever you had previously been pasting in the bearer token.To refresh the token, all you should need to do is re-run the authentication request.