Skip to main content

Variables & chaining

Real API tests are sequences: log in, use the token to create something, then read it back. Trq chains requests with variables — one request extracts a value from its response, and later requests reference it as {{var.NAME}}.

The Extract tab — pull response values into variables, shown in the Extracted response tab

Extract from a response

Open a request's Extract tab and add a row per value you want to keep: a variable name on the left, and a JSON dot-path (or /regex/) on the right.

token ← $.token
userId ← $.user.id

Paths use JSONPath-lite: a leading $. is optional, and array indexes work — data.items[0].id. After a Send, the Extracted response tab shows each variable and the value it captured, so you can confirm the path before you rely on it.

Use it downstream

Any later request references a captured value as {{var.NAME}} — in the URL, a param, a header, the auth fields, or the body:

GET {{env.baseUrl}}/users/{{var.userId}}
Authorization: Bearer {{var.token}}

That's the whole chaining model: a login request extracts token, a create request sends Bearer {{var.token}} and extracts the new id, a verify request reads /users/{{var.id}}. Three rows, no code.

Variables are run-scoped

Extracted variables live for the duration of a Run and flow top-to-bottom through the case. Only the instruction (the path) is saved in the .trq file — never the captured value — so each run reflects live data.

Sending one request in isolation

When you Send a single request that references {{var.*}}, Trq offers to first run the earlier variable-producing requests so the token is seeded — so you can author a mid-chain request without running the whole case each time.

Reusable values

Besides captured variables, Trq generates a few values once per run and reuses them across every request, so a create and its later lookup agree:

  • {{uuid}} — a random UUID ({{uuid(8)}} for a short id / substring)
  • {{randomNumber}}, {{randomString}}
  • {{timestamp}} — the run's start time

Insert them from the + Template ▾ menu (or type {{). For distinct values in the same run, add a label: {{uuid:a}} and {{uuid:b}}.

Next: point the same chain at different environments, or run the whole case.