0
0
Postmantesting~10 mins

Bearer token 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 set the Authorization header with a Bearer token in Postman.

Postman
pm.request.headers.add({ key: 'Authorization', value: 'Bearer [1]' });
Drag options to blanks, or click blank then click option'
AaccessToken
BapiKey
Ctoken
DsessionId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'apiKey' or 'sessionId' instead of the token variable.
Forgetting to include the 'Bearer ' prefix.
2fill in blank
medium

Complete the test script to check if the response has a Bearer token in the Authorization header.

Postman
pm.test('Response has Bearer token', () => { pm.expect(pm.response.headers.get('Authorization')).to.include('[1]'); });
Drag options to blanks, or click blank then click option'
ABearer
BToken
CBasic
DOAuth
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'Token' or 'Basic' which are different schemes.
Using lowercase 'bearer' which may cause case sensitivity issues.
3fill in blank
hard

Fix the error in this script that sets the Bearer token from environment variable 'authToken'.

Postman
pm.request.headers.upsert({ key: 'Authorization', value: 'Bearer [1]' });
Drag options to blanks, or click blank then click option'
Apm.variables.get('authToken')
Bpm.environment.get('authToken')
Cpm.globals.get('authToken')
Dpm.request.get('authToken')
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.variables.get() or pm.globals.get() which fetch different scopes.
Trying to get token from pm.request which is incorrect.
4fill in blank
hard

Fill both blanks to extract the Bearer token from the Authorization header and save it to an environment variable.

Postman
const authHeader = pm.response.headers.get('[1]');
const token = authHeader.split('[2]')[1].trim();
pm.environment.set('bearerToken', token);
Drag options to blanks, or click blank then click option'
AAuthorization
BBearer
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong header key like 'Auth' or 'Token'.
Splitting by ' ' (space) instead of 'Bearer ' which includes the word.
5fill in blank
hard

Fill all three blanks to write a test that verifies the Bearer token is present and not empty in the Authorization header.

Postman
pm.test('Bearer token is present and valid', () => {
  const authHeader = pm.response.headers.get('[1]');
  pm.expect(authHeader).to.exist;
  pm.expect(authHeader).to.match(/^[2]\s+\S+$/);
  const token = authHeader.split('[3]')[1];
  pm.expect(token.length).to.be.above(0);
});
Drag options to blanks, or click blank then click option'
AAuthorization
BBearer
CBearer
DToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Token' instead of 'Bearer' in regex or split.
Forgetting the space after 'Bearer' in split.