Search code examples
authenticationhttp-headerspostmanpostman-pre-request-script

Postman: Get bearer token from collection authorization in pre-request script


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?


Solution

  • 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