Apidog Docs
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
HomeLearning Center
Support CenterAPI ReferencesDownloadChangelog
HomeLearning Center
Support CenterAPI ReferencesDownloadChangelog
Discord Community
Slack Community
X / Twitter
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
  1. Using Scripts
  • Apidog Learning Center
  • Getting Started
    • Introduction to Apidog
    • Basic Concepts in Apidog
    • Navigating Apidog
    • Quick Start
      • Overview
      • Creating an Endpoint
      • Making a Request
      • Adding an Assertion
      • Creating Test Scenarios
      • Sharing API Documentation
      • Explore More
    • Migration to Apidog
      • Overview
      • Manual Import
      • Scheduled Import (Bind Data Sources)
      • Import Options
      • Export Data
      • Import From
        • Import from Postman
        • Import OpenAPI Spec
        • Import cURL
        • Import Markdowns
        • Import from Insomnia
        • Import from apiDoc
        • Import .har File
        • Import WSDL
  • Design APIs
    • Overview
    • Create a New API Project
    • Endpoint Basics
    • APl Design Guidelines
    • Module
    • Configure Multiple Request Body Examples
    • Components
    • Common Fields
    • Global Parameters
    • Endpoint Change History
    • Comments
    • Batch Endpoint Management
    • Custom Protocol API
    • Schemas
      • Overview
      • Create a New Schema
      • Build a Schema
      • Generate Schemas from JSON Etc
      • oneOf, allOf, anyOf
      • Using Discriminator
    • Security Schemes
      • Overview
      • Create a Security Scheme
      • Use the Security Scheme
      • Security Scheme in Online Documentation
    • Advanced Features
      • Custom Endpoint Fields
      • Associated Test Scenarios
      • Endpoint Status
      • Appearance of Parameter Lists
      • Endpoint Unique Identification
  • Develop and Debug APIs
    • Overview
    • Generating Requests
    • Sending Requests
    • Debugging Cases
    • Test Cases
    • Dynamic Values
    • Validating Responses
    • Design-First vs Request-First
    • Generating Code
    • Environments & Variables
      • Overview
      • Environment Management
      • Using Variables
    • Vault Secrets
      • Overview
      • HashiCorp Vault
      • Azure Key Vault
      • AWS Secrets Manager
    • Pre and Post Processors
      • Assertion
      • Extract Variable
      • Wait
      • Overview
      • 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
          • Modifying Requests
          • Other Examples
      • Database Operations
        • Overview
        • MySQL
        • MongoDB
        • Redis
        • Oracle Client
    • Dynamic Values Modules
  • Mock API Data
    • Overview
    • Smart Mock
    • Custom Mock
    • Mock Priority Sequence
    • Mock Scripts
    • Cloud Mock
    • Self-Hosted Runner Mock
    • Mock Language (Locales)
  • API Testing
    • Overview
    • Test Scenarios
      • Create a Test Scenario
      • Pass Data Between Requests
      • Flow Control Conditions
      • Sync Data from Endpoints and Endpoint Cases
      • Import Endpoints and Endpoint Cases from Other Projects
      • Export Test Scenarios
    • Run Test Scenarios
      • Run a Test Scenario
      • Run Test Scenarios in Batch
      • Manage Runtime Environment of APIs from Other Projects
      • Data-Driven Testing
      • Scheduled Tasks
    • Test Suite
      • Overview
      • Create A Test Suite
      • Orchestrate Test Suite
      • Run Test Suites Locally
      • Run Test Suites Via CLI
      • Scheduled tasks
    • Test Reports
      • Test Reports
    • Test APIs
      • Integration Testing
      • Performance Testing
      • End-to-End Testing
      • Regression Testing
      • Contract Testing
    • Apidog CLI
      • Overview
      • Installing and Running Apidog CLI
      • Apidog CLI Options
    • CI CD
      • Overview
      • Integrate with Gitlab
      • Integrate with Jenkins
      • Trigger Test by Git Commit
      • Integrate with Github Actions
  • Publish API Docs
    • Overview
    • API Technologies Supported
    • Quick Share
    • Viewing API Documentation
    • Markdown Documentation
    • Publishing Documentation Sites
    • Custom Login Page
    • Custom Layouts
    • Custom CSS, JavaScript, HTML
    • Custom Domain
    • LLM-Friendly Features
    • SEO Settings
    • Advanced Settings
      • Documentation Search
      • CORS Proxy
      • Integrating Google Analytics with Doc Sites
      • Folder Tree Settings
      • Visibility Settings
      • Embedding Values in Document URLs
    • API Versions
      • Overview
      • Creating API Versions
      • Publishing API Versions
      • Sharing Endpoints with API Versions
  • Send Requests
    • Overview
    • SSE Debugging
    • MCP Client
    • Socket.IO
    • WebSocket
    • Webhook
    • SOAP or WebService
    • GraphQL
    • gRPC
    • Use Request Proxy Agents for Debugging
    • Create Requests
      • Request History
      • Request Basics
      • Parameters and Body
      • Request Headers
      • Request Settings
      • Debug Requests
      • Saving Requests as Endpoints
      • HTTP/2
    • Response and Cookies
      • Viewing API Responses
      • Managing Cookies
      • Overview
    • Authentication and Authorization
      • Overview
      • CA and Client Certificates
      • Authorization Types
      • Digest Auth
      • OAuth 1.0
      • OAuth 2.0
      • Hawk Authentication
      • Kerberos
      • NTLM
      • Akamai EdgeGrid
  • Branches
    • Overview
    • Creating a Sprint Branch
    • Testing APIs in a Branch
    • Designing APIs in a Branch
    • Merging Sprint Branches
    • Managing Sprint Branches
  • AI Features
    • Overview
    • Enabling AI Features
    • Generating Test Cases
    • Modifying Schemas with AI
    • Endpoint Compliance Check
    • API Documentation Completeness Check
    • AI-Powered Field Naming
    • FAQs
  • Apidog MCP Server
    • Overview
    • Connect Apidog Project to AI
    • Connect Published Documentation to AI
    • Connect OpenAPI Files to AI
  • Best Practices
    • Handling API Signatures
    • Accessing OAuth 2.0 Protected APIs
    • Collaboration Workflow
    • Managing Authentication State
  • Offline Space
    • Overview
  • Administration
    • Managing Teams
      • Managing Teams
      • Managing Team Members
      • Member Roles & Permission Settings
      • Team Activities
      • Team Resources
        • General Runner
        • Team Variables
        • Request Proxy Agent
      • Real-time Collaborations
        • Team Collaboration
    • Onboarding Checklist
      • Basic Concepts
      • Onboarding Guide
    • Managing Projects
      • Managing Projects
      • Managing Project Members
      • Notification Settings
      • Project Resources
        • Database Connection
        • Git Connection
    • Managing Organization
      • Managing Organization
      • Single Sign-On (SSO)
        • SSO Overview
        • Configuring Microsoft Entra ID
        • Configuring Okta
        • Configuring SSO for an Organization
        • Managing User Accounts
        • Mapping Groups to Teams
      • SCIM Provisioning
        • Introduction to SCIM Provisioning
        • Microsoft Entra ID
        • Okta
      • Plans Management
        • Billing Managers in Organizations
      • Organization Resources
        • Self-Hosted Runner
  • Billing
    • Overview
    • Credits
    • Alternative Payment Methods
    • Managing Subscriptions
    • Upgrading Your Plan
    • Moving Paid Teams to Organizations
  • Data & Security
    • Data Storage and Security
    • User Data Privacy and Security
    • Request Routing and Data Security
  • Add-ons
    • API Hub
    • Apidog Intellij IDEA Plugin
    • Browser Extension
      • Chrome
      • Microsoft Edge
    • Request Proxy
      • Request Proxy in Web
      • Request Proxy in Shared Docs
      • Request Proxy in Client
  • Account & Preferences
    • Account Settings
    • Generating OpenAPI Access Token
    • Notification
    • Language Settings
    • Hot Keys
    • Network Proxy Configuration
    • Backing Up Data
    • Updating Apidog
    • Deleting Account
    • Experimental Features
  • References
    • API Design-First Approach
    • Apidog OpenAPI Specificaiton Extensions
    • JSONPath
    • XPath
    • Regular Expressions
    • JSON Schema
    • CSV File Format
    • Installing Java Environment
    • Runner Deployment Environment
    • Apidog flavored Markdown
  • Apidog Europe
    • Apidog Europe
  • Support Center
HomeLearning Center
Support CenterAPI ReferencesDownloadChangelog
HomeLearning Center
Support CenterAPI ReferencesDownloadChangelog
Discord Community
Slack Community
X / Twitter
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
  1. Using Scripts

Calling Other Programming Languages

Apidog allows you to execute external programs (scripts, JARs, binaries) from your Javascript environment. This enables you to leverage existing code in languages like Java, Python, PHP, Go, Shell, etc.
Security Notice
External programs run outside the Apidog sandbox and have full access to your system. Ensure you trust the code you are executing.

Supported Languages#

Apidog infers the execution command based on file extensions:
LanguageExtensionCommand Prefix
Java.jarjava -jar
Python.pypython
Node.js.jsnode
PHP.phpphp
Go.gogo run
Shell.shsh
Ruby.rbruby
Lua.lualua

How to Call External Programs#

1.
Open External Program Directory: Click the folder icon in the script editor to open the directory where your external scripts should be placed.
External Program Directory
2.
Execute via Script: Use pm.executeAsync to call the program.

API Reference#

pm.executeAsync#

filePath string External program path
args string[] Parameters. When calling specified methods in a jar package, JSON.stringify will be used for conversion. Except for that, non-string types will be implicitly converted to string.
options Object
command string The execution command of the external program, the first part of "command prefix" is the execution command. Optional, default value is inferred automatically (see "command prefix" table above), can be customized to any program.
cwd string Working directory of the subprocess. Optional, default is "External Programs Directory".
env Record<string, string> Environment variables of the subprocess. Optional, default is {}.
windowsEncoding string Encoding used on Windows system. Optional, default is "cp936".
className string Specify the class name to call in the jar package, e.g. "com.apidog.Utils".
method string Specify the method name to call in the jar package, e.g. "add".
paramTypes string[] Specify the parameter types of the method to call in the jar package, e.g. ["int", "int"].
Return: Promise<string>
Usage of command parameter
By default Apidog uses python to execute .py files. If python3 is already installed on the computer, command can be specified as python3.

pm.execute#

It is recommended to use pm.executeAsync instead.
pm.execute(filePath, args, options)
filePath string External program path
args string[] Parameters. When calling specified methods in a jar package, JSON.stringify will be used for conversion. Except for that, non-string types will be implicitly converted to string.
options Object
windowsEncoding string Encoding used on Windows system. Optional, default is "cp936".
className string Specify the class name to call in the jar package, e.g. "com.apidog.Utils".
method string Specify the method name to call in the jar package, e.g. "add".
paramTypes string[] Specify the parameter types of the method to call in the jar package, e.g. ["int", "int"].
Return: string

Execution and Logs#

When executing a program, the executed command will be printed in the console (for reference only). If the result does not meet expectations, you can copy the command and paste it in Shell/CMD to debug.
The console will also print the "standard output (stdout)" and "standard error output (stderr)" of the executed process. The stdout content (excluding the trailing newline character) will be the final result of the execution.
TIP
For historical reasons, pm.execute treats execution as failed when there is content in stderr. This causes some programs to fail when outputting warnings or error messages. pm.executeAsync changes to use the exit code of the process to determine if the execution failed.

Input and Output of External Programs#

Parameters#

Since the specified external program runs with command line execution, it can only get the passed in parameters through command line arguments.
For example, in script pm.executeAsync('add.js', [2, 3]), the actual executed command is node add.js 2 3. To get the parameters in the external script add.js:
TIP
1.
Different programming languages have different ways to get command line arguments, please refer to corresponding language docs.
2.
The type of command line arguments is always string, need to convert based on actual types.

Return Value#

As mentioned above, Apidog uses the stdout content as the result of program execution. So printing content to stdout can return results.
For example, in script const result = await pm.executeAsync('add.js', [2, 3]), the result can be returned by:
1.
Different programming languages have different ways to print to stdout, refer to corresponding language docs.
2.
The return type is string, need to convert based on actual types.
3.
The trailing newline character of the result will be trimmed.
4.
When calling specified methods in jar packages, the return value of the called method will be used as the final return value.

Throwing Errors#

Throwing errors can fail the current task and stop execution. For example:
1.
Different programming languages have different ways to throw errors, refer to corresponding docs.
2.
In JavaScript, console.error('Error') only prints to stderr instead of throwing an error. Consider this while using other languages too.

Debug Information#

Since pm.executeAsync uses exit code instead of stderr to determine success, stderr can be used to print debug information without affecting execution.
For example:
TIP
1.
Only pm.executeAsync supports this way of printing debug info.
2.
Different programming languages have different ways to print to stderr, refer to corresponding docs.

Migrate From pm.execute to pm.executeAsync#

Since the return value of pm.executeAsync is Promise type, execute cannot be directly changed to executeAsync. But you can use async/await to migrate with minimal changes.
TIP
Apidog version 2.3.24 or later(CLI version 1.2.38 or later) supports top-level await.
Steps:
1.
Change execute to executeAsync
2.
Add await before function call

Call Specified Methods in .jar Packages#

TIP
This feature requires Apidog version to be 2.1.39 or later. It only supports calling jars with reflection, not jars like Spring Boot using internal runtime reflection.
By default, calling a jar will invoke the main method in the Main class. If options.className is specified, it will override the default behavior and call the specified method in the jar instead.
Calling specified methods in jars is different from other external programs. Apidog will use a built-in executor to find the method in the jar by reflection and call it. If the called method has a return value, it will be used as the final return value after converting to string. Otherwise, it works the same as other calls, using stdout content as return value.
For example:
The actually executed command is:
Where <app-dist>/assets/JarExecuter-1.1.0-jar-with-dependencies.jar is the built-in executor, responsible for finding the method com.apidog.Test.combine(String,String) in the user program ./scripts/jar-1.0-SNAPSHOT.jar through reflection, and calling it with parameters (JSON string) "hello" and "world".
TIP
paramTypes is optional. If not specified, types will be inferred automatically based on parameters. Integers are inferred as "int", floats as "double", booleans as "boolean", strings as "String", arrays are inferred based on the first element, e.g. [3] is inferred as "int[]", [3.14] as "double[]", etc.
If the inferred types do not match the actual parameter types of the called method, paramTypes needs to be specified manually.
Supported values in paramTypes array: "Number"、"int"、"Integer"、"long"、"Long"、"short"、"Short"、"float"、"Float"、"double"、"Double"、"boolean"、"Boolean"、"String"、"Number[]"、"int[]"、"Integer[]"、"long[]"、"Long[]"、"short[]"、"Short[]"、"float[]"、"Float[]"、"double[]"、"Double[]"、"boolean[]"、"Boolean[]"、"String[]"
So the paramTypes in the example above can be omitted:

Examples#

1. PHP Program#

Script:
test.php:

2. Jar Program#

Script:
com.apidog.utils.jar:

Common Issues#

1. Some programs require project config files and will error if missing#

Rust and Go:
Rust:
could not find `Cargo.toml` in `<...>/ExternalPrograms` or any parent directory
Go:
go.mod file not found in current directory or any parent directory; see 'go help modules'
Solution: Use pm.executeAsync and specify cwd.

2. MacOS has built-in Python 3 but no Python 2#

Use pm.executeAsync and set command to "python3".

3. Command xxx not found#

Install corresponding program and add necessary directories to system PATH. See docs for Java installation.

4. Calling external scripts prints garbled on some Windows systems#

Set windowsEncoding to 'utf-8'
Modified atΒ 2026-01-14 09:10:00
Previous
Postman Scripts Reference
Next
Using JS Libraries
Built with