0
0
Postmantesting~10 mins

API key authentication 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 add the API key as a header in the request.

Postman
pm.request.headers.add({ key: 'Authorization', value: '[1]' });
Drag options to blanks, or click blank then click option'
AApi-Key 12345
BKey 12345
CToken 12345
DBearer 12345
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Bearer' instead of 'Api-Key' prefix.
Using 'Token' or 'Key' which are not standard prefixes here.
2fill in blank
medium

Complete the code to set the API key as a query parameter named 'api_key'.

Postman
pm.request.url.addQueryParams([{ key: 'api_key', value: '[1]' }]);
Drag options to blanks, or click blank then click option'
A12345
Bkey123
CAPIKEY
Dapikey
Attempts:
3 left
💡 Hint
Common Mistakes
Using the parameter name instead of the key value.
Using uppercase or different strings that are not the key.
3fill in blank
hard

Fix the error in the code to correctly add the API key in the headers.

Postman
pm.request.headers.add({ key: 'X-API-KEY', value: '[1]' });
Drag options to blanks, or click blank then click option'
AAuthorization
Bapi_key
CBearer 12345
D12345
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Authorization' or 'Bearer 12345' as the value when the header key is 'X-API-KEY'.
Using the parameter name instead of the key value.
4fill in blank
hard

Fill both blanks to correctly set the API key in the request headers.

Postman
pm.request.headers.add({ key: '[1]', value: '[2]' });
Drag options to blanks, or click blank then click option'
AX-API-KEY
B12345
CAuthorization
DBearer 12345
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing header key and value.
Using 'Bearer 12345' when the key is 'X-API-KEY'.
5fill in blank
hard

Fill all three blanks to create a test script that checks if the API key header is present and correct.

Postman
pm.test('API key header is set', () => {
  pm.expect(pm.request.headers.get('[1]')).to.eql('[2]');
  pm.expect(pm.request.headers.has('[3]')).to.be.true;
});
Drag options to blanks, or click blank then click option'
AX-API-KEY
B12345
CAuthorization
Dapi_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using different header names in get and has methods.
Checking for wrong API key value.