So, here I guess I wasn’t clear My fault sorry. You should put this request in a folder called “Setup” or some such one. You could then use the runner to call setup first and the value will be there. If you want to run test manually over time, you can call this request and let it set the variable for you. Since you are storing it in the environment, it will be available to all items in your collections.
The only request you need to call is the one that sets the variable. In the
Test script for this request get the token and set it in the variable. That way when ever you need to “reset” it you can do it easily, by simply running it again. If you are using the runner, then make sure the Setup folder is first (top of the list of folders) it will run it for you before it runs the lower ones so it will, again, set the value for your run.
A more complex way, but one where you don’t have do anything to get a new token each time you run any test in the collection, is to set the value using the pm.sendRequest in the
pre-scriptto get and store it in the variable like always.
Here is the quick code list of what to do in the folder (if you put all your stuff in one folder) or collection (if you want it run every time no matter what):
- make a pm.sendRequest to get the token
- get the returned value for the token
- store the value in using: pm.environment.set(“Key_name_for_token”, token)
That should let you not have to deal with getting the token at all.
If I have a chance to show something like this I will reply here with some sample code.