Postman Request Chaining

Real workflows rarely involve one request. A shopping flow logs in, creates an order, pays for it, and checks the receipt. Each step needs data from the step before. Request chaining passes values from one response into the next request automatically, so the whole flow runs without manual copying.

The Relay Race Picture

A relay team passes a baton from runner to runner. Each runner receives the baton, runs a segment, and hands it onward. In a chain, the baton is a value such as a token or an ID, and each request is one runner.

  [1] POST /login          returns  token
         │  baton: token
         ▼
  [2] POST /orders         returns  orderId
         │  baton: orderId
         ▼
  [3] POST /orders/{id}/pay   returns  paymentId
         │  baton: orderId
         ▼
  [4] GET  /orders/{id}    checks the final status

Save a Value from a Response

Place a short script in the Post-response tab of the request that produces the value.

// Request 1: Login
const data = pm.response.json();
pm.environment.set("token", data.token);

// Request 2: Create Order
const order = pm.response.json();
pm.environment.set("orderId", order.id);

Use the Saved Value in the Next Request

Insert variables with curly braces in the URL, headers, or body.

POST {{baseUrl}}/orders/{{orderId}}/pay
Authorization: Bearer {{token}}

Control the Run Order

The Collection Runner runs requests in the order they appear in the collection. Drag requests in the sidebar to set the right sequence. Postman also lets a script override the order with pm.execution.setNextRequest.

// Jump to a named request
pm.execution.setNextRequest("Check Receipt");

// Stop the run
pm.execution.setNextRequest(null);

Branch with Conditions

Chains can choose a path based on the response.

const status = pm.response.json().status;

if (status === "pending") {
    pm.execution.setNextRequest("Wait and Retry");
} else {
    pm.execution.setNextRequest("Confirm Order");
}

Poll Until a Job Finishes

Some APIs process work in the background. A polling loop checks the job repeatedly and stops when the job completes or the retry limit arrives.

const job = pm.response.json();
let tries = Number(pm.variables.get("tries") || 0);

if (job.state !== "done" && tries < 5) {
    pm.variables.set("tries", tries + 1);
    pm.execution.setNextRequest("Check Job");
} else {
    pm.test("Job completed", function () {
        pm.expect(job.state).to.equal("done");
    });
}

The retry limit prevents an endless loop when a job never finishes.

Choose the Right Variable Scope

NeedScope
Value needed across several runsEnvironment
Value needed during one run onlyLocal (pm.variables)
Value tied to one collectionCollection

Clean Up After a Chain

Remove temporary values at the end of the final request to keep environments tidy.

pm.environment.unset("orderId");
pm.environment.unset("token");

Good Chain Design

  • Name requests by action so the run order reads like a story.
  • Add a test to every step. A broken early step then fails loudly instead of corrupting later steps.
  • Keep each request small and focused on one action.
  • Delete test data at the end, for example with a DELETE request.
  • Limit retries and delays to avoid slow runs.

Key Points

  • Chaining passes data from one response into later requests.
  • Post-response scripts save values into variables.
  • Curly braces insert saved values into following requests.
  • setNextRequest changes the run order and enables branching and polling.
  • Tests on every step catch failures early.