How to set global function in Postman?

I would like to declare a function once in a preliminary request script for my first postman request, and then use it in every request after that. I set a lot of variables for the postman object and environment variables, but I did not find a way to do the same with functions.

In a preliminary script request:

function wrapTest(param1, param2, param3) { ... } 

Then i tried

  •  postman.prototype.wrap = wrapTest; 
  •  postman.wrap = wrapTest; 
  •  postman.setGlobalVariable("wrap", wrapTest); 

In the request, I try to use this function:

 postman.wrap(one,two,three); 

resulting in "postman.wrap is not a function" in all cases.

+6
source share
1 answer

The function can be saved as a string and then deleted when used.

 var stringWrap = function wrapTest(param1, param2, param3) { ... }; postman.setEnvironmentVariable("wrap", stringWrap); var parsedFunc = eval("("+environment.wrap+")"); parsedFunc("1", 2, 3); 
+7
source

All Articles