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
Recall & Review
beginner
What is the purpose of extracting data from responses in Postman?
Extracting data from responses allows you to save values from one API call and use them in subsequent requests, enabling dynamic and chained testing.
Click to reveal answer
beginner
Which Postman feature is commonly used to extract data from a JSON response?
The pm.response.json() function is used to parse the JSON response body so you can access its properties and extract data.
Click to reveal answer
intermediate
How do you save an extracted value as an environment variable in Postman?
Use pm.environment.set('variableName', value); inside the Tests tab to save the extracted value for use in other requests.
Click to reveal answer
intermediate
Example: Extract the user ID from this JSON response:
{"user": {"id": 123, "name": "Alice"}}
Use <code>let jsonData = pm.response.json(); pm.environment.set('userId', jsonData.user.id);</code> to save the user ID as an environment variable.
Click to reveal answer
beginner
Why is it important to check the response status before extracting data?
Checking the response status ensures the request was successful (e.g., status 200) before trying to extract data, preventing errors from invalid or empty responses.
Click to reveal answer
Which Postman method parses the response body as JSON?
Apm.request.body()
Bpm.response.text()
Cpm.response.json()
Dpm.environment.get()
✗ Incorrect
pm.response.json() parses the response body as JSON so you can access its properties.
How do you save a value to an environment variable in Postman?
Apm.environment.set('varName', value);
Bpm.response.set('varName', value);
Cpm.request.set('varName', value);
Dpm.variables.save('varName', value);
✗ Incorrect
pm.environment.set('varName', value); saves a value to an environment variable.
Why should you check the response status before extracting data?
ATo speed up the test execution
BTo clear environment variables
CTo change the request method
DTo ensure the response is successful and data is valid
✗ Incorrect
Checking status confirms the response is successful before extracting data.
What type of data can you extract from a Postman response?
AOnly images
BJSON, XML, HTML, or plain text
COnly XML
DOnly JSON
✗ Incorrect
Postman can extract data from various response formats including JSON, XML, HTML, and plain text.
Which tab in Postman do you write scripts to extract data from responses?
ATests
BPre-request Script
CBody
DHeaders
✗ Incorrect
The Tests tab is where you write scripts to extract data after receiving the response.
Explain how to extract a value from a JSON response and save it as an environment variable in Postman.
Think about parsing JSON and saving variables for later use.
You got /3 concepts.
Why is it important to validate the response status before extracting data in Postman tests?
Consider what happens if the response is an error.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of extracting data from API responses in Postman?
easy
A. To reuse data in subsequent API requests
B. To change the API endpoint URL
C. To modify the request headers
D. To delete the response data
Solution
Step 1: Understand the role of data extraction
Extracting data allows you to capture values from one response to use later.
Step 2: Connect API requests using extracted data
This helps chain requests by passing data like tokens or IDs forward.
Final Answer:
To reuse data in subsequent API requests -> Option A
Quick Check:
Extract data = reuse in next requests [OK]
Hint: Extract data to pass info between requests [OK]
Common Mistakes:
Thinking extraction changes the URL
Confusing extraction with header modification
Believing extraction deletes data
2. Which Postman script correctly extracts the value of userId from a JSON response and saves it as an environment variable?
easy
A. let data = pm.response.json(); pm.environment.set('userId', data.userId);
B. pm.response.set('userId', pm.response.json().userId);
C. pm.environment.get('userId', pm.response.json().userId);
D. let userId = pm.response.set('userId');
Solution
Step 1: Use pm.response.json() to parse JSON
This method converts the response body into a JavaScript object.
Step 2: Use pm.environment.set() to save variable
Set the environment variable 'userId' with the extracted value.
Final Answer:
let data = pm.response.json(); pm.environment.set('userId', data.userId); -> Option A
Quick Check:
Parse JSON + set env variable = let data = pm.response.json(); pm.environment.set('userId', data.userId); [OK]
Hint: Use pm.response.json() then pm.environment.set() [OK]
Common Mistakes:
Using pm.response.set() which doesn't exist
Using pm.environment.get() to set variables
Not parsing JSON before accessing properties
3. Given the response body:
{"token": "abc123", "user": {"id": 42}}
What will this Postman script save in the environment variable authToken?
let jsonData = pm.response.json();
pm.environment.set('authToken', jsonData.token);
medium
A. null
B. 42
C. undefined
D. "abc123"
Solution
Step 1: Parse the JSON response
jsonData.token accesses the 'token' key which has value "abc123".
Step 2: Set environment variable with token value
pm.environment.set saves "abc123" as 'authToken'.
Final Answer:
"abc123" -> Option D
Quick Check:
jsonData.token = "abc123" [OK]
Hint: Access exact key from parsed JSON to get value [OK]
Common Mistakes:
Using user.id instead of token
Expecting number 42 instead of string token
Not parsing JSON before accessing token
4. You wrote this Postman test script to extract sessionId from the response:
let data = pm.response.json();
pm.environment.set('sessionId', data.session_id);
But the environment variable sessionId is always empty. What is the likely problem?
medium
A. pm.response.json() does not parse JSON
B. pm.environment.set() cannot save variables
C. The response JSON uses sessionId not session_id
D. You must use pm.collectionVariables.set() instead
Solution
Step 1: Check JSON key names carefully
The script uses 'session_id' but the response likely has 'sessionId' (camelCase).
Step 2: Correct key name to match response
Use data.sessionId to correctly extract the value.
Final Answer:
The response JSON uses sessionId not session_id -> Option C
Quick Check:
Key name mismatch causes empty variable [OK]
Hint: Match JSON keys exactly, including case [OK]