Back to All Questions
Question 45 of 100
Intermediate API Testing
Intermediate
Q45: How Do You Extract Values from API Responses in Postman?
⛏️Core Concept
How Do You Extract Values from API Responses in Postman?
Key Takeaways & Architecture Summary
- ✓Deserialize the response payload using pm.response.json().
- ✓Navigate the object tree to retrieve target properties.
- ✓Save extracted values into environment or collection variables.
Direct Answer Summary
To extract response values, you parse the body of the response (typically using `pm.response.json()`), navigate through the keys or arrays, and assign the target value to an active environment or collection variable for reuse in subsequent requests.
⚠️ Senior Engineering Warning (Red Flag)
Never assume the property exists without validation. If the API returns an error status (e.g., 500), your extraction script will attempt to read from a null object, crashing the suite execution.
đź’ˇ STAR Architectural Explanation & Pro Tip
Parsing dynamic arrays requires using index locators (e.g. data.items[0].id) or searching properties using find filters, which is critical for resilient data pipelines.
RestAssuredTest.java
Rest-Assured + Java// Programmatic extraction and storage in Postman tests
if (pm.response.code === 200) {
const data = pm.response.json();
const token = data.auth.token;
pm.environment.set("jwtToken", token); // Stored for subsequent requests
}