Search code examples
javascriptpostmanpostman-pre-request-script

Run pre-request script on each API request in postman


Can this randomString(length) be reused in another pre-request script instead of having in each API request in postman?

function randomString(length){
  var char ='';
  while(chars.length < length ){
    chars += Math.random().toString(36).substring(2);
  }
  returns chars.substring(0,length);
};

Solution

  • You can store the function in an environment variable and then use the eval() function.