Bird
Raised Fist0
Postmantesting~20 mins

Using extracted data in next request in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Postman Data Chaining Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the value of the variable after extraction?
You run this Postman test script after a response:
pm.test("Extract userId", () => {
  const jsonData = pm.response.json();
  pm.environment.set("userId", jsonData.user.id);
});

Given the response body:
{"user": {"id": 42, "name": "Alice"}}

What will be the value of the environment variable userId?
A42 (number)
B"42" (string)
Cundefined
Dnull
Attempts:
2 left
💡 Hint
Remember that environment variables in Postman are stored as strings.
assertion
intermediate
2:00remaining
Which assertion correctly uses extracted data in the next request?
You extracted a token in the first request and saved it as an environment variable authToken. Which assertion in the next request correctly checks the token is used in the header?
Apm.expect(pm.request.headers.get('Authorization')).to.eql('Bearer ' + pm.environment.get('authToken'));
Bpm.expect(pm.request.headers.get('Authorization')).to.eql(`Bearer ${authToken}`);
Cpm.expect(pm.request.headers.get('Authorization')).to.eql('Bearer {{authToken}}');
Dpm.expect(pm.request.headers.get('Authorization')).to.eql('Bearer authToken');
Attempts:
2 left
💡 Hint
Use pm.environment.get to access environment variables in scripts.
🔧 Debug
advanced
2:00remaining
Why does the next request fail to use extracted data?
You extracted a sessionId in the first request with:
pm.environment.set('sessionId', pm.response.json().session.id);

In the next request, you use the header:
Authorization: Bearer {{sessionId}}

But the request fails with unauthorized error. What is the most likely reason?
AThe variable sessionId is saved but the next request uses a different environment without that variable.
BThe variable sessionId is not available because environment variables require manual saving.
CThe variable sessionId was not saved because pm.environment.set was called inside pm.test block.
DThe variable sessionId is overwritten by a global variable with empty value.
Attempts:
2 left
💡 Hint
Check if the environment selected for the next request is the same as where the variable was saved.
🧠 Conceptual
advanced
2:00remaining
What is the best way to pass extracted data between requests in Postman?
You want to extract a userId from one request and use it in multiple subsequent requests. Which method ensures the data is available across all requests in the collection?
ASave the userId as a global variable using pm.globals.set.
BSave the userId as a local variable in the first request's Tests tab.
CSave the userId as an environment variable using pm.environment.set.
DSave the userId in the request body of the next request manually.
Attempts:
2 left
💡 Hint
Local variables only exist during one request execution.
framework
expert
3:00remaining
How to chain requests using extracted data with Postman Collection Runner?
You have a collection with two requests: Login and GetProfile. Login extracts a token and saves it as environment variable token. GetProfile uses this token in the Authorization header.

Which setup ensures the Collection Runner correctly passes the token from Login to GetProfile?
ARun the collection with no environment selected; token is saved globally.
BRun the collection with an environment selected; Login saves token with pm.globals.set; GetProfile uses {{token}} in header.
CRun the collection with an environment selected; Login saves token with pm.variables.set; GetProfile uses {{token}} in header.
DRun the collection with an environment selected; Login saves token with pm.environment.set; GetProfile uses {{token}} in header.
Attempts:
2 left
💡 Hint
Collection Runner uses the selected environment to share variables between requests.

Practice

(1/5)
1. What is the main purpose of extracting data from one Postman response to use in the next request?
easy
A. To speed up the test execution by skipping requests
B. To automatically generate random data for requests
C. To avoid writing tests for each request separately
D. To simulate real workflows where requests depend on each other

Solution

  1. Step 1: Understand data dependency in workflows

    In real APIs, some requests need data from previous responses to work correctly.
  2. 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.
  3. Final Answer:

    To simulate real workflows where requests depend on each other -> Option D
  4. Quick Check:

    Data extraction = simulate dependent requests [OK]
Hint: Remember: Extract to reuse data in next request [OK]
Common Mistakes:
  • Thinking extraction speeds up tests by skipping requests
  • Believing extraction replaces writing tests
  • Confusing extraction with random data generation
2. Which Postman code snippet correctly saves a value from a response JSON to an environment variable named userId?
easy
A. pm.variables.set('userId', pm.response.json().id);
B. pm.setEnvironment('userId', pm.response.json().id);
C. pm.environment.set('userId', pm.response.json().id);
D. pm.environment.save('userId', pm.response.json().id);

Solution

  1. Step 1: Identify correct method to set environment variable

    The correct method is pm.environment.set to save a variable in environment scope.
  2. Step 2: Check syntax correctness

    pm.environment.set('userId', pm.response.json().id); uses pm.environment.set('userId', pm.response.json().id); which is correct syntax and usage.
  3. Final Answer:

    pm.environment.set('userId', pm.response.json().id); -> Option C
  4. Quick Check:

    Use pm.environment.set() to save variables [OK]
Hint: Use pm.environment.set('var', value) to save data [OK]
Common Mistakes:
  • Using pm.setEnvironment which does not exist
  • Using pm.environment.save which is invalid
  • Using pm.variables.set which sets local variables, not environment
3. Given this test script in Postman after a response:
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"}?
medium
A. Authorization: Bearer {{token}}
B. Authorization: Bearer abc123
C. Authorization: Bearer pm.response.json().authToken
D. Authorization: Bearer

Solution

  1. Step 1: Extract token from response JSON

    The script saves the value of authToken which is "abc123" into environment variable token.
  2. Step 2: Use environment variable in next request header

    The header uses {{token}} which Postman replaces with the saved value "abc123".
  3. Final Answer:

    Authorization: Bearer abc123 -> Option B
  4. Quick Check:

    {{token}} replaced by saved value [OK]
Hint: Saved variables replace {{var}} placeholders automatically [OK]
Common Mistakes:
  • Expecting {{token}} to remain as literal text
  • Using wrong variable name causing empty header
  • Confusing script syntax with header value
4. You wrote this test script to save a user ID:
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?
medium
A. The JSON path is incorrect; user ID is at pm.response.json().id, not pm.response.json().user.id
B. You must use pm.variables.set instead of pm.environment.set
C. You forgot to add double curly braces around userId in the next request
D. Environment variables cannot be used in headers

Solution

  1. Step 1: Check JSON path correctness

    If the response JSON has user ID at id root, then pm.response.json().user.id is wrong and returns undefined.
  2. Step 2: Understand effect of wrong path

    Saving undefined sets empty variable, so {{userId}} is empty in next request causing failure.
  3. Final Answer:

    The JSON path is incorrect; user ID is at pm.response.json().id, not pm.response.json().user.id -> Option A
  4. Quick Check:

    Correct JSON path = correct variable value [OK]
Hint: Verify JSON path matches response structure exactly [OK]
Common Mistakes:
  • 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
5. You want to extract a session ID from a login response and use it in the next request's URL as a path parameter. The login response JSON is:
{"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}}?
hard
A. In test script: pm.environment.set('sessionId', pm.response.json().session.id); Use URL with {{sessionId}}
B. In test script: pm.variables.set('sessionId', pm.response.json().session.id); Use URL with {{sessionId}}
C. In test script: pm.environment.set('sessionId', pm.response.json().id); Use URL with {{sessionId}}
D. In test script: pm.environment.set('sessionId', pm.response.json().sessionId); Use URL with {{sessionId}}

Solution

  1. Step 1: Extract session ID correctly from nested JSON

    The session ID is at pm.response.json().session.id, so use this path to extract it.
  2. Step 2: Save to environment variable and use in URL

    Use pm.environment.set('sessionId', ...) to save it, then use {{sessionId}} in the next request URL.
  3. Final Answer:

    In test script: pm.environment.set('sessionId', pm.response.json().session.id); Use URL with {{sessionId}} -> Option A
  4. Quick Check:

    Correct path + environment set + {{var}} usage [OK]
Hint: Match JSON path exactly and use pm.environment.set [OK]
Common Mistakes:
  • 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