Oauth2 Token Re-generates for each request - How to stop this?

Hello forum,
I have been struggling for a while to automate my Oauth2 token for my collections,
I managed to build up a pre-request script and it is authenticating all my requests just fine,
trouble is that once I run a whole collection, I notice how in the console the token regenerates for each request.

So I wanted to share my script for someone else to use and if you can give me an idea of how to generate the token just once for the whole collection it would be much appreciated.

var clientId = pm.variables.get(“clientId”);

var clientSecret = pm.variables.get(“clientSecret”);

var scope = pm.variables.get(“scope”);

var urlResource = pm.variables.get(“urlResource”);

var tenant = pm.variables.get(“tenant”);

var apiEndpointVersion = pm.variables.get(“apiEndpointVersion”);


url: urlResource + tenant + apiEndpointVersion,

method: "POST",

header: [



body: {

    mode: "urlencoded",

    urlencoded: [

        {key: "client_id", value: clientId},

        {key: "client_secret", value: clientSecret},

        {key: "scope", value: scope},

        {key: "grant_type", value: "client_credentials"}




(error, response) => {

pm.variables.set("rawIdToken", response.json().access_token);

pm.variables.set("refresh_token", response.json().refresh_token);


After running the whole collection you can see how the requests for the token are pilling up:

Any ideas?