But the test fails because the variable 'status' is undefined. What is the likely cause?
medium
A. Variables set in one request are not available in another without environment or global scope.
B. pm.variables.get returns undefined if set is not awaited.
C. Missing semicolon after set statement causes failure.
D. Variable names cannot be strings.
Solution
Step 1: Understand variable scopes in Postman
Variables set with pm.variables.set are local to the current request script and do not persist across requests.
Step 2: Identify why 'status' is undefined
If you try to get 'status' in a different request without using environment or global variables, it will be undefined.
Final Answer:
Variables set in one request are not available in another without environment or global scope. -> Option A
Quick Check:
Local variables don't persist across requests [OK]
Hint: Use environment/global variables for cross-request data [OK]
Common Mistakes:
Thinking semicolons affect variable persistence
Believing get waits for set automatically
Assuming variable names can't be strings
5. You want to save a user token from a response JSON and reuse it in the next request. Which flow correctly assigns and retrieves the token using Postman variables?
hard
A. In first request test script: pm.variables.set('token', pm.response.json().token); In next request pre-request script: const token = pm.environment.get('token');
B. In first request test script: pm.variables.set('token', pm.response.json().token); In next request pre-request script: const token = pm.variables.get('token');
C. In first request test script: pm.environment.set('token', pm.response.json().token); In next request pre-request script: const token = pm.environment.get('token');
D. In first request test script: pm.environment.set('token', pm.response.json().token); In next request pre-request script: const token = pm.variables.get('token');
Solution
Step 1: Identify variable scope for cross-request use
To reuse data across requests, environment variables must be used, not local variables.
Step 2: Match correct set and get methods
In first request test script: pm.environment.set('token', pm.response.json().token); In next request pre-request script: const token = pm.environment.get('token'); uses pm.environment.set and pm.environment.get, which correctly share data between requests.
Final Answer:
Use environment variables to save and retrieve token across requests. -> Option C
Quick Check:
Environment variables persist across requests [OK]
Hint: Use environment variables for data between requests [OK]
Common Mistakes:
Using pm.variables for cross-request data
Mixing environment and local variable methods
Not retrieving variables in the correct scope
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.