Auto Writing Response Token To  Environment  In Postman

It is very easy to automatically write the token obtained when we login to the environment file. You can achieve your goal by typing the following codes in the Test section.


Step 1 - Let's create an environment with any name from the Environments section and enter our simple information.




Step 2 - Authorization settings are made within the root collection.




  1. const { token } = JSON.parse(responseBody);

  2. pm.environment.set("token", token);



Step 3 - The code block is written in the Tests section of the login request.




Step 4 - When the request is fulfilled, we will see that the token information is updated in the env.




Step 5 - In requests requiring tokens, authorization should be set to inherit auth from parent.