0
0
Postmantesting~5 mins

Setting variables from response in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of setting variables from a response in Postman?
It allows you to save data from an API response to use later in your tests or requests, making your tests dynamic and reusable.
Click to reveal answer
beginner
How do you access a JSON field named 'token' from a response in Postman test script?
Use pm.response.json().token to get the value of the 'token' field from the JSON response.
Click to reveal answer
beginner
Which Postman method is used to set an environment variable from a response?
Use pm.environment.set('variableName', value) to save a variable in the environment scope.
Click to reveal answer
intermediate
Write a simple Postman test script snippet to save the 'id' field from a JSON response as a collection variable named 'userId'.
const jsonData = pm.response.json();
pm.collectionVariables.set('userId', jsonData.id);
Click to reveal answer
beginner
Why is it better to use variables in Postman tests instead of hardcoding values?
Variables make tests flexible and maintainable by allowing reuse of dynamic data, reducing errors and manual updates.
Click to reveal answer
Which method extracts JSON data from a Postman response?
Apm.request.body()
Bpm.response.text()
Cpm.response.json()
Dpm.environment.get()
How do you set a global variable named 'sessionId' in Postman from a response value 'sid'?
Apm.globals.set('sessionId', pm.response.json().sid)
Bpm.environment.set('sessionId', pm.response.json().sid)
Cpm.collectionVariables.set('sessionId', pm.response.json().sid)
Dpm.variables.set('sessionId', pm.response.json().sid)
What is the correct way to save a response header 'Auth-Token' as an environment variable 'authToken'?
Apm.environment.get('authToken', pm.response.headers.get('Auth-Token'))
Bpm.environment.set('authToken', pm.response.headers.get('Auth-Token'))
Cpm.response.set('authToken', pm.response.headers.get('Auth-Token'))
Dpm.variables.set('authToken', pm.response.body.Auth-Token)
Which scope is NOT available for variables in Postman?
ASession
BEnvironment
CGlobal
DCollection
Why should you check if a response field exists before setting a variable from it?
ATo clear all variables
BTo speed up the test execution
CTo automatically retry the request
DTo avoid errors if the field is missing
Explain how to extract a value from a JSON response and save it as an environment variable in Postman.
Think about parsing JSON and setting variables in Postman scripts.
You got /3 concepts.
    Describe why setting variables from responses is useful in API testing with Postman.
    Consider how tests behave when data changes.
    You got /3 concepts.