Apicat Docs
  1. Using scripts
Apicat Docs
  • What is Apicat?
  • Send requests
    • Create requests
      • Request basics
      • Parameters and body
      • Request headers
      • Request settings
      • Dynamic values
      • HTTP/2
      • SOAP/WebService
    • Authentication and authorization
      • Overview
      • CA and client certificates
      • Authorization types supported by Apidog
      • Digest Auth
      • OAuth 1.0
      • OAuth 2.0
      • Hawk Authentication
      • Kerberos
      • NTLM
      • Akamai EdgeGrid
    • Response and cookies
      • Overview
      • API response in Apidog
      • Create and send cookies
      • Debug requests
    • Dynamic values Modules
      • Airline
      • Animal
      • Color
      • Commerce
      • Company
      • Database
      • Datatype
      • Date
      • Finance
      • Food
      • Git
      • Hacker
      • Helpers
      • Image
      • Internet
      • Location
      • Lorem
      • Music
      • Number
      • Person
      • Phone
      • Science
      • String
      • System
      • Vehicle
      • Word
  • Environments & variables
    • Overview
    • Using variables
    • Environments & services
  • Pre/Post processors
    • Overview
    • Assertion
    • Extract variable
    • Wait
    • Database operations
      • Overview
      • MySQL
      • MongoDB
      • Redis
      • Oracle Client
    • Using scripts
      • Overview
      • Pre processor scripts
      • Post processor scripts
      • Public scripts
      • Postman scripts reference
      • Calling other programming languages
      • Using JS libraries
      • Visualizing responses
      • Script examples
        • Assertion scripts
        • Using variables in scripts
        • Using scripts to modify request messages
        • Other examples
  • Best practices
    • How to handle API signatures
    • How to access OAuth 2.0 protected APIs
    • Apidog collaboration workflow
    • Managing authentication state in Apidog
  • Account & preferences
    • Account settings
    • Generate OpenAPI access token
    • Language settings
    • Hot keys
    • Network proxy configuration
    • Data backup
    • Updating Apidog
    • Deleting account
    • Experimental Features
  • References
    • API-Design First Approach
    • Apidog OpenAPI/Swagger Specificaiton Extensions
    • JSONPath
    • XPath
    • Regular Expressions
    • JSON Schema
    • CSV File Format
    • Install Java Environment
    • Runner deployment environment
    • Apidog flavored Markdown
  1. Using scripts

Public scripts

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.

Usage#

Manage public scripts#

Go to settings -> public script to manage your public scripts.
CleanShot 2025-06-11 at 11.54.16@2x.png

Reference public scripts#

You can directly reference public scripts in the preprocessor and postprocessor in API Execution Page or API Use Case page.
image.png
The public scripts are executed before all the other scripts.
The execution of multiple public scripts occurs in the same order as their addition.

Referencing public scripts in other scripts#

Scripts can call each other:
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.

Practical Example#

1
Example: Declare a Simple Global Function
Define a global function within a public script so that it can be accessed by other scripts.
CleanShot 2025-06-11 at 11.58.56@2x.png
2
Call the Public Script
In the Pre Processors or Post Processors tab of an endpoint, first add the public script. Then, add a custom script and call the function declared in the public script.
CleanShot 2025-06-11 at 12.05.47@2x.png
Note: The public script must be added first in order for its methods to be accessible in subsequent custom scripts.
Modified at 2025-06-25 07:57:16
Previous
Post processor scripts
Next
Postman scripts reference
Built with