0
0
Postmantesting~10 mins

Token management in variables in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Apm.environment.get('authToken')
Bpm.request.url
Cpm.response.code
Dpm.response.json().token
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.
2fill in blank
medium

Complete the code to retrieve the stored token from environment variables.

Postman
const token = [1];
Drag options to blanks, or click blank then click option'
Apm.environment.set('authToken')
Bpm.environment.get('authToken')
Cpm.variables.get('authToken')
Dpm.request.headers.get('authToken')
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.
3fill in blank
hard

Fix 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'
Aresponse.token
Bpm.response.body.token
Cpm.response.json().token
Dpm.request.body.token
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.
4fill in blank
hard

Fill 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'
Apm.environment.get('authToken')
Bpm.environment.set('authToken')
Cpm.response.json().token
Dpm.request.headers.get('Authorization')
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.
5fill in blank
hard

Fill 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'
Apm.response.json().access_token
Btoken
Cpm.environment.get('authToken')
Dpm.response.json().token
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names for token.
Checking the wrong variable in the test assertion.