Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to save the token value into an environment variable.
Postman
pm.environment.set('authToken', [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.request.url instead of the response to get the token.
Trying to get the token from environment variable before setting it.
✗ Incorrect
The token is extracted from the JSON response using pm.response.json().token and saved into the environment variable 'authToken'.
2fill in blank
mediumComplete the code to retrieve the stored token from environment variables.
Postman
const token = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.environment.set() instead of get() to retrieve the token.
Trying to get token from request headers instead of environment variables.
✗ Incorrect
pm.environment.get('authToken') retrieves the token stored in environment variables.
3fill in blank
hardFix the error in the code to correctly set the token variable.
Postman
pm.environment.set('token', [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.body.token which is undefined because body is a string.
Trying to get token from pm.request.body which is the request, not response.
✗ Incorrect
pm.response.json().token correctly parses the JSON response and accesses the token property.
4fill in blank
hardFill both blanks to create a header with the stored token for authorization.
Postman
pm.request.headers.add({ key: 'Authorization', value: 'Bearer [1]' });
const token = [2]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.environment.set() instead of get() to retrieve the token.
Trying to get token from response instead of environment variables.
✗ Incorrect
The token is retrieved from environment variables using pm.environment.get('authToken') and used in the Authorization header.
5fill in blank
hardFill all three blanks to extract the token, save it, and verify it is set correctly.
Postman
const token = [1]; pm.environment.set('authToken', [2]); pm.test('Token is set', () => pm.expect([3]).to.not.be.undefined);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names for token.
Checking the wrong variable in the test assertion.
✗ Incorrect
The token is extracted from pm.response.json().access_token, saved using pm.environment.set with the variable token, and verified by checking pm.environment.get('authToken') is not undefined.