Use this file to discover all available pages before exploring further.
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.
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:
// Set a timestamp variablepm.environment.set('timestamp', Date.now());// Generate a random request IDpm.environment.set('requestId', Math.random().toString(36).substring(7));console.log('Request ID:', pm.variables.get('requestId'));
Post-response scripts run after the response is received. Use them to:
Write assertions and tests
Extract data from responses
Set variables based on response data
Log response information
Example:
// Test status codepm.test('Status code is 200', function() { pm.response.to.have.status(200);});// Extract token from responseconst jsonData = pm.response.json();pm.environment.set('authToken', jsonData.token);console.log('Token saved:', jsonData.token);
// Get a variableconst baseUrl = pm.environment.get('baseUrl');// Set a variablepm.environment.set('userId', '12345');// Check if variable existsif (pm.environment.has('apiKey')) { console.log('API key is configured');}// Unset a variablepm.environment.unset('tempValue');
Variables set via pm.environment.set() are automatically persisted to the active environment. New variables are created if they don’t exist.
Manage global variables (available across all environments):
// Get a global variableconst apiVersion = pm.globals.get('apiVersion');// Set a global variablepm.globals.set('lastRequestTime', Date.now());// Check if global existsif (pm.globals.has('orgId')) { console.log('Organization ID is set globally');}// Unset a global variablepm.globals.unset('tempGlobal');
Access variables from all scopes with automatic resolution:
// Get variable (resolves Environment → Collection → Global)const baseUrl = pm.variables.get('baseUrl');// Set variable in current environmentpm.variables.set('requestCount', 42);
pm.variables.get() follows the layered resolution order: Environment → Collection → Global. The narrowest scope wins.
Access response data (only available in post-response scripts):
// Get status codeconst status = pm.response.code;console.log('Status:', status);// Get response timeconst time = pm.response.responseTime;console.log('Response time:', time, 'ms');// Parse JSON responseconst jsonData = pm.response.json();console.log('User ID:', jsonData.id);// Get response body as textconst bodyText = pm.response.text();// Access response headersconst contentType = pm.response.headers.get('Content-Type');
Make HTTP requests from within scripts. This enables token fetching, dynamic lookups, and multi-step API workflows:
// Simple GET requestpm.sendRequest('https://api.example.com/health', function (err, res) { console.log('Health check status:', res.code);});// POST request with headers and bodypm.sendRequest({ url: 'https://api.example.com/auth/token', method: 'POST', header: { 'Content-Type': 'application/json' }, body: { raw: JSON.stringify({ client_id: pm.environment.get('clientId'), grant_type: 'client_credentials' }) }}, function (err, res) { if (!err) { const token = res.json().access_token; pm.environment.set('authToken', token); console.log('Token acquired'); }});
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.
// Generate timestampconst timestamp = Date.now();pm.environment.set('timestamp', timestamp);// Create signature (pseudo-code - use crypto library in real implementation)const message = pm.request.method + pm.request.url + timestamp;const signature = generateHMAC(message, pm.environment.get('secretKey'));pm.environment.set('signature', signature);console.log('Signature generated for timestamp:', timestamp);
Set dynamic headers
// Set request ID headerconst requestId = Math.random().toString(36).substring(7);pm.environment.set('requestId', requestId);// Set timestamppm.environment.set('timestamp', new Date().toISOString());console.log('Request ID:', requestId);
Conditional variable setting
// Set different base URLs based on timeconst hour = new Date().getHours();if (hour >= 9 && hour < 17) { pm.environment.set('baseUrl', 'https://api.example.com');} else { pm.environment.set('baseUrl', 'https://api-night.example.com');}console.log('Using base URL:', pm.environment.get('baseUrl'));
pm.test('Response time is acceptable', function() { pm.expect(pm.response.responseTime).to.be.below(500);});pm.test('Response size is reasonable', function() { const bodySize = pm.response.text().length; pm.expect(bodySize).to.be.below(100000); // 100KB});console.log('Response time:', pm.response.responseTime, 'ms');console.log('Response size:', pm.response.text().length, 'bytes');
Chain requests with variables
pm.test('User created successfully', function() { pm.response.to.have.status(201); const jsonData = pm.response.json(); // Save user ID for next request pm.environment.set('userId', jsonData.id); console.log('User created with ID:', jsonData.id); console.log('Use {{userId}} in the next request');});
Chain requests with pm.sendRequest
// Fetch a token, then verify the user with a follow-up callconst userId = pm.response.json().id;pm.sendRequest({ url: 'https://api.example.com/users/' + userId, method: 'GET', header: { 'Authorization': 'Bearer ' + pm.environment.get('authToken') }}, function (err, res) { pm.test('Follow-up GET returns the created user', function () { pm.expect(res.code).to.equal(200); pm.expect(res.json().id).to.equal(userId); });});
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.