1

In postman I have a collection, where each request uses collection-level Bearer Token authorization.

Collection Authorization

Now, what I would like to do is to send http request in my pre-request script (For refreshing access token), but I don't know is it possible to get access token (from collection Authorization) in pre-request scripts. I know I can get collection variables like

pm.collectionVariables.get("key),

but is there also a way to get (and also set) value from Authorization?

Boris Boskovic
  • 113
  • 2
  • 8

1 Answers1

1

You can set the Token as a collection variable {{my_token}} and then use pm.collectionVariables.set("my_token", "tokenvaluehere") in your pre-request script.

enter image description here

Pranaya Tomar
  • 199
  • 1
  • 13
  • How do we automatically handle the case when token is expired ? – insanely_sin Jul 26 '22 at 07:05
  • @insanely_sin You can handle the response in the Test script. Tests execute after the request is completed. See - https://learning.postman.com/docs/writing-scripts/test-scripts/ – Pranaya Tomar Jul 27 '22 at 07:11