Skip to content

Scripts

Scripts let you attach JavaScript snippets to individual HTTP requests. They run in a sandboxed context with access to the request and response data.

Runs before the request is sent. Use it to:

  • Log request details with console.log()
  • Modify request properties programmatically
  • Prepare dynamic data

Available API:

VariableTypeDescription
consoleobjectconsole.log(), console.warn(), console.error(), console.info() for debugging
request.methodstringHTTP method (GET, POST, etc.)
request.urlstringThe request URL
request.headersobjectKey-value map of request headers
request.paramsobjectKey-value map of query parameters
request.bodystringRaw request body
// Pre-request script example
console.log('Sending', request.method, 'to', request.url)
console.log('Headers:', JSON.stringify(request.headers))

Runs after the response is received. All pre-request variables are available, plus:

VariableTypeDescription
response.statusCodenumberHTTP status code (e.g. 200)
response.statusTextstringStatus text (e.g. “OK”)
response.headersobjectKey-value map of response headers
response.bodystringRaw response body
response.contentTypestringContent-Type header value
// Post-response script example
console.log('Status:', response.statusCode, response.statusText)
console.log('Response body:', response.body)
if (response.statusCode === 200) {
console.log('Request succeeded!')
} else {
console.warn('Request failed with status', response.statusCode)
}
  1. Open a request
  2. Click the Scripts tab
  3. Write JavaScript in the Pre-request Script or Post-response Script textarea
  4. Send the request — scripts execute automatically

Script output from console.log/warn/error/info appears in the script logs panel below the editors. Each entry includes:

  • Log type (log, warn, error, info)
  • Timestamp
  • Message content
// Pre-request: Log the request
console.log('Starting request to', request.url)
// Post-response: Validate the response
if (response.statusCode >= 400) {
console.error('Error:', response.statusCode, response.body)
} else {
console.log('Success:', response.statusCode)
const data = JSON.parse(response.body)
console.log('Items count:', data.length)
}