Public scripts are designed to re-use scripts and avoid repetitions of the same scripts in different places.You can place the scripts with the same methods and classes in the public scripts and reference the script directly in your API requests.
When normal scripts need to call variables or methods in public scripts, you should not use APIs of setting types such as pm.sendRequest or pm.environments.setcause they will fail. We recommend writing pure functions and returning them.
Public scripts can call each other.
Postprocessor scripts can call preprocessor scripts.
All scripts are executed within their own scope to prevent variable conflicts between them (wrapped by closures). When local variables or local methods are declared with var, let, const, or function other scripts cannot call those variables and methods. You must convert a variable or method to a global variable or global method if you want other scripts to use it.Variable Example:
Recommend:
Function Example:
Recommend:
You need to make sure there are no conflicts in global variable or global method naming between scripts.
For API use cases, you need to add public scripts in preprocessor or postprocessor scripts in order to use it.
You need to TIP to the order of calls when referencing scripts. Only scripts that are executed later can make calls to scripts that were executed before.