Scripting API
Tigrister's scripting engine gives you full programmatic control over your HTTP requests. The tg object available in every pre-request and post-response script lets you read and modify requests, inspect responses, manage environment variables, and share data across flow steps.
The tg Object
Four namespaces, each serving a distinct purpose:
- tg.request — Access and modify the HTTP request. Mutable in pre-scripts, read-only in post-scripts.
- tg.response — Access response data including status, headers, body, and timing. Available only in post-scripts.
- tg.environment — Read and write environment variables. Changes are persisted immediately and available in subsequent requests.
- tg.flow — Read and write flow-scoped variables for cross-step data sharing. Only available inside Flow Runner execution.
Request Modification
Pre-scripts can modify the request before it's sent — add headers, change the URL, or rewrite the body dynamically.
| Property / Method | Type | Pre-Script | Post-Script |
|---|---|---|---|
tg.request.url | string | read / write | read-only |
tg.request.method | string | read-only | read-only |
tg.request.headers | object | read (copy) | read (copy) |
tg.request.body | string | undefined | read / write | read-only |
tg.request.setHeader(key, value) | void | adds/updates header | — |
tg.request.removeHeader(key) | void | removes header | — |
// Pre-script: Add dynamic auth header
const token = tg.environment.get('auth_token');
if (token) {
tg.request.setHeader('Authorization', 'Bearer ' + token);
}
Response Inspection
Post-scripts have full access to the response — status code, headers, body, and performance timing.
| Property / Method | Type | Description |
|---|---|---|
tg.response.status | number | HTTP status code |
tg.response.statusText | string | HTTP status text |
tg.response.headers | object | Response headers |
tg.response.body | string | Raw response body |
tg.response.json() | any | Cached JSON parser — safe to call multiple times |
tg.response.timing | object | Breakdown: total, dns, tls, ttfb (ms) |
// Post-script: Extract tokens from login response
if (tg.response.status === 200) {
const data = tg.response.json();
tg.environment.set('auth_token', data.access_token);
tg.environment.set('refresh_token', data.refresh_token);
}
Environment Variables
Variables set with tg.environment.set() are persisted immediately and referenced as {{varName}} in URL, headers, body, params, and auth fields.
| Method | Description |
|---|---|
tg.environment.get(key) | Returns value or undefined |
tg.environment.set(key, value) | Sets and persists immediately |
tg.environment.has(key) | Returns true if exists |
Works across all contexts — standalone requests, project requests, and flow steps. The active environment depends on context: global, project, or flow group.
Flow Variables
Share data between flow steps with ephemeral variables. Unlike environment variables, flow variables exist only for the current flow run.
| Method | Description |
|---|---|
tg.flow.get(key) | Returns value or undefined |
tg.flow.set(key, value) | Sets for current iteration |
tg.flow.has(key) | Returns true if exists |
Referenced as {{flow.varName}} in any subsequent step's URL, headers, body, or assertions.
// Step 1 post-script: Extract user data
const data = tg.response.json();
tg.flow.set('userId', String(data.id));
tg.flow.set('token', data.token);
// Step 2 URL: {{base_url}}/api/users/{{flow.userId}}
// Step 2 Header: Authorization: Bearer {{flow.token}}
Additional Globals
| Global | Description |
|---|---|
console.log() / warn() / error() | Log to Script Output panel (capped at 1000 chars) |
fetch(url, options) | Make HTTP requests from within scripts |
setTimeout(fn, ms) | Delay execution within a script |
All scripts have a 30-second execution limit.
Tigrister's scripting API turns your API client into a full automation platform — from simple token extraction to complex multi-step workflows with conditional logic and data chaining.