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 managing tokens in variables in Postman?
Managing tokens in variables allows you to reuse authentication tokens across multiple requests without hardcoding them. This makes tests easier to maintain and more secure.
Click to reveal answer
beginner
How do you store an authentication token in a Postman environment variable?
This saves the token from the response to the environment variable named 'token'.
Click to reveal answer
beginner
Why is it better to use environment or global variables for tokens instead of hardcoding them in requests?
Using variables helps keep tokens secure and makes it easy to update tokens in one place. Hardcoding tokens can lead to errors and security risks if tokens expire or change.
Click to reveal answer
beginner
What is a common way to use a stored token in the Authorization header of a Postman request?
You can use the variable in the header like this:
Authorization: Bearer {{token}}
Postman replaces {{token}} with the stored token value when sending the request.
Click to reveal answer
intermediate
How can you automate token refresh in Postman when a token expires?
You can write a Pre-request Script that checks if the token is expired and requests a new token automatically, then updates the variable with the new token before the main request runs.
Click to reveal answer
What is the best place to store an API token in Postman for reuse?
AIn an environment variable
BHardcoded in the request URL
CIn the request body
DIn the console log
✗ Incorrect
Storing tokens in environment variables allows easy reuse and updating without changing each request.
How do you reference a stored token variable in a Postman request header?
A$token
B#token#
C{{token}}
D%token%
✗ Incorrect
Postman uses double curly braces {{variableName}} to insert variable values.
Which script section in Postman is best to update a token variable after receiving a new token?
AAuthorization script
BPre-request script
CBody script
DTests script
✗ Incorrect
The Tests script runs after the response and can extract and save tokens from the response.
Why should you avoid hardcoding tokens directly in requests?
ATokens expire and need updating
BIt makes requests slower
CIt causes syntax errors
DIt disables the API
✗ Incorrect
Hardcoded tokens become invalid when expired, requiring manual updates.
What is a benefit of automating token refresh in Postman?
AMakes requests slower
BEnsures tests run without manual token updates
CDisables environment variables
DRemoves the need for authentication
✗ Incorrect
Automating token refresh keeps tests running smoothly without manual intervention.
Explain how to store and use an API token in Postman variables for multiple requests.
Think about scripts and variable syntax in Postman.
You got /4 concepts.
Describe a strategy to handle token expiration automatically in Postman tests.
Consider scripting automation in Postman.
You got /4 concepts.
Practice
(1/5)
1. In Postman, why is it useful to store an authentication token in an environment variable?
easy
A. To make the token visible to all users of the Postman app
B. To encrypt the token for security
C. To automatically refresh the token without any scripting
D. To reuse the token across multiple requests without re-authenticating each time
Solution
Step 1: Understand token reuse in Postman
Storing a token in an environment variable allows multiple requests to access it easily without needing to get a new token each time.
Step 2: Evaluate other options
Making the token visible to all users or automatic refresh without scripting is not true by default. Encryption is not automatic either.
Final Answer:
To reuse the token across multiple requests without re-authenticating each time -> Option D
Quick Check:
Token reuse = B [OK]
Hint: Tokens stored in variables enable reuse across requests [OK]
Common Mistakes:
Thinking tokens auto-refresh without scripts
Assuming variables encrypt tokens automatically
Believing tokens are shared with all users by default
2. Which of the following is the correct way to set a token value to an environment variable in Postman test script?
easy
A. pm.environment.set('token', response.token);
B. pm.setEnvironmentVariable('token', response.token);
C. pm.environment.token = response.token;
D. pm.variables.set('token', response.token);
Solution
Step 1: Identify the current Postman syntax for setting environment variables
The correct method is pm.environment.set('variableName', value) in Postman scripts.
Step 2: Check other options for correctness
pm.setEnvironmentVariable is deprecated, direct assignment is invalid, and pm.variables.set sets local variables, not environment variables.
Final Answer:
pm.environment.set('token', response.token); -> Option A
Quick Check:
Use pm.environment.set() to set env variables [OK]
Hint: Use pm.environment.set('name', value) to set env variables [OK]
Common Mistakes:
Using deprecated pm.setEnvironmentVariable method
Trying to assign variables directly like pm.environment.token
Confusing local and environment variables
3. Given this Postman test script snippet after a login request:
let jsonData = pm.response.json();
pm.environment.set('authToken', jsonData.token);
What will be the value of {{authToken}} in the next request if the response JSON is {"token": "abc123"}?
medium
A. null
B. undefined
C. "abc123"
D. pm.response.json()
Solution
Step 1: Extract token from response JSON
The script gets the token value "abc123" from the response JSON using pm.response.json().token.
Step 2: Set environment variable 'authToken'
The token value "abc123" is stored in the environment variable 'authToken' using pm.environment.set.
Final Answer:
"abc123" -> Option C
Quick Check:
Stored token = "abc123" [OK]
Hint: Stored token equals JSON token value from response [OK]
Common Mistakes:
Assuming variable is undefined if not explicitly declared
Confusing variable name with function call
Expecting null instead of actual token string
4. You wrote this test script to save a token:
let jsonData = pm.response.json();
pm.environment.set('token', jsonData.authToken);
But the token is not saved. What is the most likely reason?
medium
A. You must use pm.variables.set instead
B. The response JSON does not have a key named 'authToken'
C. pm.environment.set is deprecated and does not work
D. Tokens cannot be saved in environment variables
Solution
Step 1: Check the JSON key used in script
The script tries to access jsonData.authToken, so the response must have that key.
Step 2: Verify if the response JSON contains 'authToken'
If the response uses a different key like 'token', jsonData.authToken will be undefined and nothing is saved.
Final Answer:
The response JSON does not have a key named 'authToken' -> Option B
Quick Check:
Key mismatch causes undefined token [OK]
Hint: Check JSON key names match exactly in script [OK]
Common Mistakes:
Assuming pm.environment.set is deprecated
Using pm.variables.set for environment variables
Believing tokens can't be saved in environment variables
5. You want to automatically refresh an expired token in Postman by chaining requests. Which approach correctly manages the token variable for reuse?
hard
A. Use a pre-request script in all requests to check token expiry and request a new token if expired, then update the environment variable
B. Manually update the token variable in Postman UI before each request
C. Store the token in a global variable and never update it
D. Hardcode the token in the request headers and do not use variables
Solution
Step 1: Understand token expiry handling
Tokens expire, so scripts must check expiry and refresh tokens automatically to avoid failures.
Step 2: Use pre-request scripts to automate token refresh
Pre-request scripts can check if the token is expired and call the authentication endpoint to get a new token, then update the environment variable.
Step 3: Evaluate other options
Manual updates are error-prone, global variables without updates cause failures, and hardcoding tokens is insecure and inflexible.
Final Answer:
Use a pre-request script in all requests to check token expiry and request a new token if expired, then update the environment variable -> Option A
Quick Check:
Automate token refresh with pre-request scripts [OK]
Hint: Automate token refresh in pre-request scripts [OK]