Describe the issue
Team members are using environment variables to set request variable values in their pre-request scripts (not just headers, URL endpoints, etc.). This, as expected, is causing scope pollution with bloated env files, headache collisions to debug, etc.
For example, to generate a unique email at the time of sending a request, team members are:
- Generating a unique email value in the pre-request script
- Assigning this value to an environment variable in the pre-request script
- Using the environment variable value in the key-value pairs in the request body
The best practice is to scope variables to as specific a level as possible. Despite digging through documentation and searching forums, I have found no way to access and update any variables used in the request body from the pre-request script.
There are no repro steps or expected behavior to list because it is a matter of non-existent (or not yet found?) features.
What should it look like?
What I want is to have something like this in a pre-request script:
const randomlyGeneratedEmail = () => //returns String of email using base and timestamp;
const email = randomlyGeneratedEmail();
pm.setRequestVariable('email', email); //this method does not exist
And then in the body of the request I would have this key-value pair of âemailâ: â{{email}}â which would use the value I set in the pre-request script.
Either that, or I should be able to access the pre-request script variables from the key-value pairs in the request body. What weâre doing now does not work and I need a working solution for variable scope.