What if your tests could talk to each other and share data automatically, saving you hours of tedious work?
Why Using extracted data in next request in Postman? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine testing an online store API where you first create a user, then need to use that user's ID to add items to their cart. Doing this manually means copying the user ID from one response and pasting it into the next request every time.
This manual copying is slow and easy to mess up. You might copy the wrong ID or forget to update it, causing tests to fail or give wrong results. It's like writing down a phone number on paper and then dialing it by hand every time--tedious and error-prone.
Using extracted data in the next request automates this process. Postman can grab the needed data from one response and automatically insert it into the next request. This saves time, reduces mistakes, and makes your tests reliable and repeatable.
POST /createUser // Copy userId from response POST /addToCart Body: {"userId": "copied_id_here", "item": "book"}
POST /createUser pm.environment.set('userId', pm.response.json().id); POST /addToCart Body: {"userId": "{{userId}}", "item": "book"}
This lets you build smooth, connected test flows that mimic real user actions without lifting a finger to copy data.
For example, when testing a signup and login flow, you can create a user, extract their token, and use that token automatically in the login request to verify access--all in one automated run.
Manual copying of data between requests is slow and error-prone.
Extracting data automatically ensures accuracy and speed.
It enables building realistic, connected test scenarios easily.
Practice
Solution
Step 1: Understand data dependency in workflows
In real APIs, some requests need data from previous responses to work correctly.Step 2: Recognize the role of data extraction
Extracting data lets you pass dynamic values from one request to the next, simulating real user flows.Final Answer:
To simulate real workflows where requests depend on each other -> Option DQuick Check:
Data extraction = simulate dependent requests [OK]
- Thinking extraction speeds up tests by skipping requests
- Believing extraction replaces writing tests
- Confusing extraction with random data generation
userId?Solution
Step 1: Identify correct method to set environment variable
The correct method ispm.environment.setto save a variable in environment scope.Step 2: Check syntax correctness
pm.environment.set('userId', pm.response.json().id); usespm.environment.set('userId', pm.response.json().id);which is correct syntax and usage.Final Answer:
pm.environment.set('userId', pm.response.json().id); -> Option CQuick Check:
Use pm.environment.set() to save variables [OK]
- Using pm.setEnvironment which does not exist
- Using pm.environment.save which is invalid
- Using pm.variables.set which sets local variables, not environment
pm.environment.set('token', pm.response.json().authToken);And the next request uses the header:
Authorization: Bearer {{token}}What will be the value of the Authorization header if the response JSON is
{"authToken": "abc123"}?Solution
Step 1: Extract token from response JSON
The script saves the value ofauthTokenwhich is "abc123" into environment variabletoken.Step 2: Use environment variable in next request header
The header uses{{token}}which Postman replaces with the saved value "abc123".Final Answer:
Authorization: Bearer abc123 -> Option BQuick Check:
{{token}} replaced by saved value [OK]
- Expecting {{token}} to remain as literal text
- Using wrong variable name causing empty header
- Confusing script syntax with header value
pm.environment.set('userId', pm.response.json().user.id);But the next request using
{{userId}} fails with an empty value. What is the most likely cause?Solution
Step 1: Check JSON path correctness
If the response JSON has user ID atidroot, thenpm.response.json().user.idis wrong and returns undefined.Step 2: Understand effect of wrong path
Saving undefined sets empty variable, so{{userId}}is empty in next request causing failure.Final Answer:
The JSON path is incorrect; user ID is at pm.response.json().id, not pm.response.json().user.id -> Option AQuick Check:
Correct JSON path = correct variable value [OK]
- Using wrong JSON path causing undefined variable
- Confusing pm.variables.set with pm.environment.set
- Forgetting to use {{}} in next request
- Thinking environment variables can't be used in headers
{"session": {"id": "sess789"}}Which is the correct way to extract and use this session ID in the next request URL
https://api.example.com/data/{{sessionId}}?Solution
Step 1: Extract session ID correctly from nested JSON
The session ID is atpm.response.json().session.id, so use this path to extract it.Step 2: Save to environment variable and use in URL
Usepm.environment.set('sessionId', ...)to save it, then use{{sessionId}}in the next request URL.Final Answer:
In test script: pm.environment.set('sessionId', pm.response.json().session.id); Use URL with {{sessionId}} -> Option AQuick Check:
Correct path + environment set + {{var}} usage [OK]
- Using wrong JSON path like pm.response.json().id
- Using pm.variables.set which is temporary
- Using incorrect variable name in URL
- Extracting from wrong JSON key
