← Back to Overview

TESTING

Scripting API

Complete reference for all objects and globals available inside pre-request and test scripts.

request Object

Available in pre-request scripts only. Read/write access — modifications affect the outgoing request.

PropertyTypeDescription
request.urlstringFull request URL (after variable interpolation)
request.methodstringHTTP method (GET, POST, etc.)
request.headersKeyValue[]Push to add, filter to remove. Each: {key, value, enabled}
request.bodyRequestBodyRequest body object (type, raw, formData, graphql, etc.)
Note: Modifying request in test scripts has no effect — the request has already been sent.

response Object

Available in test scripts only. Read-only access to the full HTTP response.

PropertyTypeDescription
response.statusnumberHTTP status code
response.statusTextstringStatus text ("OK", "Not Found")
response.headersRecord<string, string>Response headers (lowercase keys)
response.bodystringRaw response body text
response.json()anyParsed JSON (throws if body is not valid JSON)
response.timenumberResponse time in milliseconds
response.sizenumberResponse body size in bytes
response.cookiesCookieEntry[]Parsed cookies from Set-Cookie headers

environment Object

Available in both pre-request and test scripts. Read/write access to the active environment.

MethodReturnsDescription
environment.get(key)string | undefinedGet variable value from active environment
environment.set(key, value)voidSave variable to active environment
environment.has(key)booleanCheck if variable exists
environment.unset(key)voidRemove variable from environment

console

Available in both scripts. Output appears in the Test Results tab under "Script Logs".

MethodBehavior
console.log(...args)Output shown in script logs
console.assert(condition, message)Failed assertion = test failure
console.warn(...args)Also captured in script logs
console.error(...args)Also captured in script logs

Built-in Globals

Standard JavaScript globals available in the sandbox:

JSON Math Date parseInt parseFloat encodeURIComponent decodeURIComponent atob btoa Buffer crypto setTimeout RegExp Array Object String / Number

crypto.randomUUID() generates UUIDs. Buffer.from() / .toString() for encoding. setTimeout is limited to max 5 seconds.

Limitations

5-second execution timeout — scripts that exceed this are terminated
No require/import — cannot load external modules
No file system accessfs is not available
No network requestsfetch, http are not available
No process/os access — fully sandboxed from the host system
Cannot import external libraries — only built-in globals are available
Error handling: Errors thrown in scripts are caught and displayed as script failures in the Test Results tab. They do not prevent the request from sending (pre-request) or the response from displaying (test).

Next

Ko-fi