Scripts
Customize your API requests and responses using Workflow scripts
Maxim Workflows provide powerful scripting capabilities to modify requests and responses. These scripts help you transform data, add authentication, and handle complex response structures.
Request Modification
The prescript
function runs before sending requests to your API. Use it to modify request parameters, add headers, or transform data.
All script hooks also support asynchronous operation. You can define them as async
functions, for example: async function prescript(request) { ... }
.
Response Processing
The postscriptV2
function processes API responses before displaying them. Use it to transform response data or extract specific fields:
Conversation Management
Use these scripts to set up and clean up multi-turn conversation tests:
Variable Management
Maxim’s scripts flow providers a robust programmatic access to manage variable across the simulation course. Each sandbox has access to 4 methods
Add a new variable
Adds a variable to the simulation context using the given key and value. The variable remains accessible throughout the entire simulation.
Get a variable
Retrieves the value of a variable that was previously added to the simulation context, or provided by the dataset during test runs. Returns undefined
if the variable is not found in the current context.
Set a variable
Sets the value of an existing variable in the simulation context, or creates it if it doesn’t exist. Use this to update the value of a variable at any point during the simulation.
Get a vault variable
This method allows you to securely retrieve a variable stored in the vault. Vault variables are typically used for secrets or sensitive data that should not be exposed in plain text. If the variable does not exist in the vault, this method will return undefined.
Available Libraries
You don’t need to use require
or import
to use these modules in scripts. These are directly available in the script environment.
axios
: Axios is a popular HTTP client library for JavaScript. It provides a simple API for making HTTP requests and supports various features like request and response interceptors, request cancellation, and automatic JSON parsing.fetch
: Fetch is a modern web API for making HTTP requests in JavaScript. It provides a promise-based interface for fetching resources and supports features like streaming, request/response customization, and automatic JSON parsing.
Need access to more libraries in javascript sandbox?
Reach out to us if you need access to any other node libraries in the sandbox.