When you need to set your auth token for all your Rest endpoints, you can make use of the environment variables in postman. You can achieve this in two ways, first is manually and other through the code.we will see both ways in this post
Setting the environment variables manually
First, get your all data ready that is needed to generate the token. i.e Auth token URL, client ID(App ID), client secret, scope URL, username and password. Once you have all these data, you can hit the AuthURL with grant type ‘password’.You can set the environment variable in the following way.

After adding the token URL , and other data .Click on send which will generate the access_token.

After the access token is generated , Goto Manage environment by click on the gear icon

After that Add an Environment and then all the variables in the environment.

In the same way, you all can add all other variables required to pass data dynamically.

Just we need to make sure about the scope of the variables. To understand the scope you can check my other post.
Setting the environment variables through script.
You can also set the environment variable through the script also.
Go to the “Tests” section in the postman and add the below script. Please add the script in the same request which is generating the token.
var responseData = JSON.parse(responseBody);
pm.environment.set("token", responseData.access_token);

After the variable value is set in either ways. you can use this token in other requests.To access any environment variable in any of your request , call the variable by passing the variable name in {{variable_name}}.
