Overview
Apidog contains a Javascript-based scripting engine. You can use scripts (JavaScript code snippets) to add dynamic behavior to API requests or collection tests.
What can be achieved with scripts:
- Test (assert) the correctness of the results returned by the request (postprocessor script).
- Modify API request parameters dynamically, such as adding API signature parameters, etc (preprocessor script).
- Pass data between API requests (using scripts to manipulate variables).
- Directly call programs written in other languages. We support java(.jar), python, PHP, JS, BeanShell, go, shell, Ruby, Lua, etc.
:::tip[]
Apidog script syntax is compatible with Postman script syntax. Postman scripts can be seamlessly migrated to Apidog.
See all pm syntax supported here.
:::
:::highlight purple
For those unfamiliar with JavaScript, writing pm scripts can be challenging. To address this, we recommend using the Apidog Script Generator to simplify script writing. Simply describe the script you want in natural language, and the generator will create a runnable script for you.
:::
Usage
Scripts can be added in the following two stages:
- Use preprocessor scripts before sending the request to the server.
- Use the postprocessor script (assertion) after receiving the response.
Debugging Scripts
You can write debugging scripts in preprocessor and postprocessor so you can log output information through console.log("message") in the console.
pm.console.log("anything")
Examples
- Assertion scripts
- Using variables in scripts
- Using scripts to modify request messages
- Other examples
FAQ
Q: Does Apidog support pm.nextRequest()
?
A: Apidog does not have a "Run collection" functionality, so it cannot use pm.nextRequest()
. The corresponding method is to create a test scenario in the Tests module, and then add an if condition, so that you can make different requests under different conditions.