Blog

Variables from an API response: pass the order id to the next request

Every new order on staging gets a new id. You copy it from the response, paste it into the next request’s address, then into a third one, and somewhere you get one digit wrong. An “After response” rule in Microkoi Bench takes the value from the body, a header or a cookie, and the next requests fill it in themselves.

Why copying ids breaks the check

Checking an order in a delivery app takes three or four requests in a row: create the order, fetch it, change the note for the courier, cancel it. All of them except the first depend on its response.

An id copied by hand goes stale with the first new order. The request goes out with the old id, the server answers 404 or, worse, 200 for someone else’s order, and ten minutes go into hunting for a bug that isn’t there.

What the order creation response contains

POST /orders response
HTTP/1.1 201 Created
ETag: "v1-9c41"
Set-Cookie: session=s-5d2e8b71a0; Path=/; HttpOnly

{
  "data": {
    "id": "ord-48213",
    "status": "created",
    "deliveryAt": "2026-11-17T19:30:00+03:00"
  }
}

The next requests need three values from three places: the order id from the body, the order version from the ETag header and the session from a cookie.

The fastest way: from the response Model

  1. Send the order creation request.
  2. In the response, open Body → “Model” and hover over the id field.
  3. Click “Save to variable” to the right of the field.
  4. The editor switches to the “After response” tab and selects the variable name. Replace id with orderId and press Enter.

The value is taken from this response right away, no need to send the request again. In “Model” the field is now tagged with the variable name, so you can see it’s already passed on.

Headers and cookies: a rule by hand

On the “After response” tab, click “Add rule” and fill in the row. A body path is written the same way as in “Model”, but with the array index: data.id, data.items[0].id.

“From”“Path”“Variable”
“Body”data.idorderId
“Header”ETagetag
“Cookie”sessionsession

For a header, the path is its name; for a cookie, the name from Set-Cookie. If the request has been sent before, a “From the last response” hint appears under the path field with every path in the response, its type and an example value.

Use the values in the next request

Write the variable in curly braces in the address, parameters, headers, body or auth:

Changing the order note
PATCH {{baseUrl}}/orders/{{orderId}}
If-Match: {{etag}}
Cookie: session={{session}}

{ "comment": "Call 10 minutes before arrival" }

Create a new order, and the update request goes out with its id, version and session right away. A variable that’s in neither “This run” nor the environment shows before you send: it’s highlighted in red with a wavy underline. If you send such a request anyway, it still goes out, and a “Variables not found: …” warning appears above the response.

How to tell the rule worked

The “Last value” column shows what the rule took from the last response:

What you seeWhat to do
A valueNothing: the rule works
“Send to see the value”Send the request from this tab
“Not in the last response”Check that the field comes in this response
“Taken only from a 2xx response”Look into the server error
“Check the path and name”Fix the typo in the path or name

Rules run only after a 2xx response. A 404 with an error message won’t overwrite a good orderId, and a dropped request won’t leave an empty value.

Where the values live

Captured values go into the “This run” layer. A button with that name and the number of values appears on the right of the tab bar and shows which request took which value. The layer overrides the active environment and lives while Bench is open. It isn’t written to files.

If you need the value after a restart, click the server button on the rule — “Also update “orderId” in environment “Staging””. The value is then written to the active environment too.

Sessions and tokens are secrets. The lock on a rule hides the value behind dots in history, logs and reports. Token and session fields saved from “Model” are marked as secrets automatically.

The same rules link chain steps

Put “Create order” and “Change note” into one chain as steps: the first step’s rule passes orderId to the second, and the arrow between them shows which value went on. How to build a chain from a scenario you’ve already recorded is in “A request chain from traffic: an API scenario without manual setup”.

What you get

Checking a new order is a few “Send” clicks in a row, with no clipboard. A request won’t go out with yesterday’s id, and a server error won’t spoil a value taken from a good response.

Try “After response” rules in beta 0.9.6 and write to beta@microkoi.com about which part of the response you most often need values from. We read every email.

Microkoi BenchAPI clientCollections, environments, history

Try it on your own project

The beta is free and needs no sign-up. Download it, pick your project folder and start the proxy — your first requests will show up within minutes.

Version 0.9.6 · macOS, Windows and Linux · no sign-up