Scripts & Automation
Write pre-request and test scripts in JavaScript to automate workflows and extract variables from responses.
Pre-Request Scripts
Scripts that run before the request is sent. Use them to:
- Set dynamic headers or parameters
- Generate timestamps or random values
- Log debug information
Test Scripts
Scripts that run after the response is received. Use them to:
- Extract values from the response and save as variables
- Validate response status codes and body
- Chain requests by passing data between them
Script API
VortexHQ scripts use a Postman-compatible JavaScript API:
// Access response
const body = vx.response.json();
const status = vx.response.status;
// Set variables
vx.variables.set('userId', body.data.id);
vx.variables.set('token', body.token);
// Get variables
const baseUrl = vx.variables.get('base_url');
// Assertions
vx.test('Status is 200', () => {
vx.expect(status).toBe(200);
});
vx.test('Has user data', () => {
vx.expect(body.data).toBeDefined();
vx.expect(body.data.name).toBeType('string');
});
Console Output
Use console.log() in scripts — output appears in the response console panel.