Bird
Raised Fist0
Postmantesting~10 mins

Using extracted data in next request in Postman - Interactive Code Practice

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to extract the token from the response and save it as an environment variable.

Postman
pm.environment.set('authToken', pm.response.json().[1]);
Drag options to blanks, or click blank then click option'
Aerror
Bstatus
Ctoken
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect key names like 'status' or 'message' instead of 'token'.
Not using pm.response.json() to parse the response.
2fill in blank
medium

Complete the code to use the extracted token in the Authorization header of the next request.

Postman
pm.request.headers.add({ key: 'Authorization', value: 'Bearer ' + pm.environment.get('[1]') });
Drag options to blanks, or click blank then click option'
AtokenValue
BaccessToken
CsessionToken
DauthToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that was not set previously.
Forgetting to add 'Bearer ' before the token.
3fill in blank
hard

Fix the error in the test script to correctly extract the user ID from the response and save it.

Postman
let userId = pm.response.json().[1];
pm.environment.set('userId', userId);
Drag options to blanks, or click blank then click option'
Auserid
Bid
Cuser_id
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user_id' or 'userid' which may not exist in the response.
Using wrong case like 'userId' if the response uses 'id'.
4fill in blank
hard

Fill both blanks to create a test that checks if the extracted token is not empty and saves it.

Postman
let token = pm.response.json().[1];
if (token [2] '') {
    pm.environment.set('authToken', token);
}
Drag options to blanks, or click blank then click option'
Atoken
B!==
C==
DaccessToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!==' causing wrong condition.
Using wrong key name like 'accessToken' if the response uses 'token'.
5fill in blank
hard

Fill all three blanks to extract 'id' and 'name' from the response and save them as environment variables if 'id' is greater than 0.

Postman
let data = pm.response.json();
let userId = data.[1];
let userName = data.[2];
if (userId [3] 0) {
    pm.environment.set('userId', userId);
    pm.environment.set('userName', userName);
}
Drag options to blanks, or click blank then click option'
Aid
Bname
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'userId' or 'userName' if response uses 'id' and 'name'.
Using '<' instead of '>' causing wrong condition.

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