Perform GetAuthToken request before performing Request

We’re using an api that use a Bearer Token auth system. Recently they updated their api to not use a persistent token anymore and we have to get a new token prior to calling the api.

Is there a way to setup a PostMan request in a way that it will perform an Auth request and save the auth token and then use that token in the request being activated?

Hi @hfhInventio,

You can do this in the preRequest script section using pm.request.

See the link below on how to send request via scripting.

I added a Pre-Request Script on the Collection I need this done on. Saved the result in a CollectionVariable called ‘access_token’ and use {{access_token}} on each request authorization page that needs a new Bearer Token for each call.
Even made the script only refresh the token once per hour as to not spam the auth service too much.

Thanks.