Script Types
LiteClient provides two types of scripts:- Pre-Request Scripts
- Post-Response (Test) Scripts
Pre-request scripts run before the request is sent. Use them to:
- Set environment variables dynamically
- Generate authentication tokens or signatures
- Modify request state
- Log pre-request information
The pm API
LiteClient provides a Postman-compatiblepm API for interacting with environments, globals, requests, and responses.
pm.environment
Manage environment variables:Variables set via
pm.environment.set() are automatically persisted to the active environment. New variables are created if they don’t exist.pm.globals
Manage global variables (available across all environments):pm.variables
Access variables from all scopes with automatic resolution:pm.variables.get() follows the layered resolution order: Environment → Collection → Global. The narrowest scope wins.pm.request
Access request metadata (available in both pre-request and post-response scripts):pm.response
Access response data (only available in post-response scripts):pm.test()
Write assertions and tests:pm.expect()
ChaiJS-style assertions:pm.sendRequest()
Make HTTP requests from within scripts. This enables token fetching, dynamic lookups, and multi-step API workflows:pm.sendRequest() is limited to 5 calls per script execution and shares the 10-second script timeout. The callback receives (error, response) where response has .code, .status, .headers, .json(), and .text() methods.Console Logging
Use standard console methods for debugging:Console output appears in the Tests tab after request execution. Output is capped at 200 entries per script.
Script Examples
Pre-Request Script Examples
Generate HMAC signature
Generate HMAC signature
Set dynamic headers
Set dynamic headers
Conditional variable setting
Conditional variable setting
Post-Response Script Examples
Extract and save token
Extract and save token
Validate response structure
Validate response structure
Performance testing
Performance testing
Chain requests with variables
Chain requests with variables
Chain requests with pm.sendRequest
Chain requests with pm.sendRequest
Script Execution
Sandboxed Environment
Scripts run in a Node.js VM sandbox with the following constraints:- 10-second timeout - Scripts that exceed 10 seconds are automatically terminated
- 100KB size limit - Scripts larger than 100KB are rejected
- 200 console entries - Console output is capped at 200 entries
- 200 test results - Test results are capped at 200 tests
- 5
pm.sendRequest()calls - HTTP requests from scripts are capped at 5 per execution
Error Handling
When scripts fail, errors are displayed in the Tests tab with line numbers:Postman Import/Export
Scripts are fully preserved when importing and exporting Postman Collection v2.1 files:- Pre-request scripts are imported as-is
- Test scripts are imported as post-response scripts
- Collection-level and folder-level scripts show a warning (not yet supported)
LiteClient currently supports request-level scripts only. Collection-level and folder-level scripts from Postman collections are not executed.
Best Practices
Keep scripts simple and focused
Keep scripts simple and focused
Write concise scripts that do one thing well. Complex logic is harder to debug and maintain. Break large workflows into multiple requests.
Use descriptive test names
Use descriptive test names
Name tests clearly so failures are easy to understand: “Status code is 200”, “Response contains user ID”, “Email format is valid”.
Log important state changes
Log important state changes
Use
console.log() to track variable changes, token generation, and workflow progress. This helps with debugging.Handle missing data gracefully
Handle missing data gracefully
Check if properties exist before accessing them to avoid script errors:
Use variables for reusability
Use variables for reusability
Extract tokens, IDs, and other dynamic values into variables so subsequent requests can use them. This enables request chaining.