Script files
A script file is a .js file that sends your saved requests by their # @name, with real logic between them: loops,
branches, waiting for a job to finish, checks. Use one when a runbook would be all steps
and no text.
A .js file that calls send("…") appears in the tree as a script; other .js files, such as request handlers, stay
hidden. Right-click a folder and choose New script… to start from a template.
const index = input("indexName", "products-v2"); // asks, and sets {{indexName}}confirm(`Copy every document into ${index}?`); // "no" stops the script
const start = send("startReindex"); // the request named startReindexvars.set("jobId", start.body.jobId); // {{jobId}} for the requests after this
poll(() => send("reindexStatus"), { until: r => r.body.state === "done", failIf: r => r.body.state === "failed", every: "30s", giveUpAfter: "2h",});
send("swapAlias", { alias: "products" }); // a value for this request onlylog("Reindex finished");send runs a request exactly as pressing Send would: the same environment, @variables, client.global
values, scripts, cookies and chaining. While you type send(", the folder’s request names are suggested.
Running it
Section titled “Running it”Press Run (or Ctrl+Enter). The output lists each log line and each request in order;
select a request to see its response. Stop cancels the script, even while it’s waiting.


Unlike request scripts, a script file has no 30-second limit.
On the command line: reqjet run reindex.js --env dev --var indexName=products-v3. --var answers input(), and
--yes answers confirm().
| Function | What it does |
|---|---|
send("name", { key: value }) |
Sends a request and returns its response: status, ok (a 2xx status), body, text, headers.valueOf(name) and tests. The name is looked up in the script’s folder and below; use "file.http#name" when it’s in more than one file. The optional values apply to that request only. A request that gets no response throws an error. |
vars.get(name), vars.set(name, value) |
The script’s values. Every request it sends sees them as {{name}}, before anything else. |
env.get(name) |
A value from the selected environment. |
resolve("{{baseUrl}}/x") |
Fills in {{variables}} as a request would. |
input(name, default, description) |
Asks for a value and sets it as {{name}}. Cancelling stops the script. |
confirm(message) |
Asks before going on. “No” stops the script, and a try/catch doesn’t catch that. |
poll(fn, { until, failIf, every, giveUpAfter }) |
Calls fn until until(result) holds. It fails when failIf(result) holds, or after giveUpAfter. The defaults are 10s and 30m. |
sleep("5s") |
Waits. |
log(...) |
Writes to the output. |
test(name, fn), assert(condition, message) |
Records pass or fail checks. |
client.global |
The session’s script values, shared with request scripts. |
The request script helpers, such as reqjet.http.get, jsonPath and crypto, work too.