Skip to main content
LiteClient supports JavaScript scripting to automate API workflows. Write pre-request scripts to set variables or generate tokens before requests are sent, and post-response scripts to validate responses and extract data.

Script Types

LiteClient provides two types of 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
Example:

The pm API

LiteClient provides a Postman-compatible pm 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

Post-Response Script Examples

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
Scripts have no access to the file system or VS Code APIs. Network access is available only via pm.sendRequest(). They run in an isolated environment for security.

Error Handling

When scripts fail, errors are displayed in the Tests tab with line numbers:
Use try-catch blocks in complex scripts to handle errors gracefully and provide meaningful error messages.

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

Write concise scripts that do one thing well. Complex logic is harder to debug and maintain. Break large workflows into multiple requests.
Name tests clearly so failures are easy to understand: “Status code is 200”, “Response contains user ID”, “Email format is valid”.
Use console.log() to track variable changes, token generation, and workflow progress. This helps with debugging.
Check if properties exist before accessing them to avoid script errors:
Extract tokens, IDs, and other dynamic values into variables so subsequent requests can use them. This enables request chaining.