Clone
3
API Reference
Pavel Baksy edited this page 2026-05-18 17:37:35 +02:00
API Reference
JavaScript API available in Roster Scripts.
Language: JavaScript (ES5+) via GJS Execution: Synchronous, sandboxed
Request Object (preprocessing only)
| Property | Type | Description |
|---|---|---|
request.method |
string | "GET", "POST", "PUT", "DELETE" |
request.url |
string | Full URL |
request.headers |
object | Header key-value pairs |
request.body |
string | Request body |
All properties are writable.
Response Object (postprocessing only)
| Property | Type | Description |
|---|---|---|
response.body |
string | Response body |
response.headers |
object | Header key-value pairs |
response.statusCode |
number | HTTP status code |
response.statusText |
string | Status text ("OK", ...) |
response.responseTime |
number | Response time in ms |
All properties are read-only.
Roster API (both contexts)
| Method | Available in | Description |
|---|---|---|
roster.getVariable(name) |
preprocessing | Returns string or null |
roster.setVariable(name, value) |
both | Creates or updates variable |
roster.setVariables({...}) |
both | Batch set |
roster.project.name |
preprocessing | Current project name |
roster.project.environments |
preprocessing | Array of environment names |
Variable names must match /^\w+$/ (alphanumeric + underscore). Values are always strings. Sensitive variables are automatically routed to/from GNOME Keyring.
Console
console.log(...) and console.error(...) — output appears in the Preprocessing/Postprocessing results tab.
Available Built-ins
Standard JS built-ins: Date, JSON, Math, String, Array, Object, etc.
No fetch, setTimeout, require, or file system access.
Type Notes
Variables are always strings. Convert when needed:
roster.setVariable('count', data.count.toString());
const count = parseInt(roster.getVariable('count'), 10);
Examples
Authentication flow
POST /auth/login — postprocessing:
const data = JSON.parse(response.body);
roster.setVariables({
access_token: data.access_token,
refresh_token: data.refresh_token,
user_id: data.user_id
});
Authenticated request — preprocessing:
const token = roster.getVariable('access_token');
request.headers['Authorization'] = 'Bearer ' + token;
Dynamic headers
request.headers['X-Request-ID'] = Math.random().toString(36).slice(2);
request.headers['X-Timestamp'] = new Date().toISOString();