0
0
Postmantesting~20 mins

API key authentication in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Key Authentication Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the response status code when API key is missing?

You send a GET request to an API endpoint that requires an API key in the header X-API-Key. You omit this header. What is the expected HTTP status code in the response?

Postman
GET /data HTTP/1.1
Host: api.example.com

A500 Internal Server Error
B200 OK
C401 Unauthorized
D403 Forbidden
Attempts:
2 left
💡 Hint

Think about what status code means 'authentication required but missing or invalid'.

assertion
intermediate
2:00remaining
Which assertion correctly verifies API key authentication success?

You have a Postman test script that checks if the API key authentication succeeded by verifying the response status code is 200. Which assertion is correct?

Postman
pm.test('API key auth success', function() {
    // Fill in assertion here
});
Apm.response.to.have.status(200);
Bpm.response.to.have.status(401);
Cpm.response.to.have.status(403);
Dpm.response.to.have.status(500);
Attempts:
2 left
💡 Hint

Success means the server accepted the API key and returned OK.

locator
advanced
2:00remaining
Identify the best header locator for API key in Postman test script

In a Postman test script, you want to check the value of the API key sent in the request header X-API-Key. Which code correctly accesses this header?

Apm.response.headers.get('X-API-Key')
Bpm.response.getHeader('X-API-Key')
Cpm.request.getHeader('X-API-Key')
Dpm.request.headers.get('X-API-Key')
Attempts:
2 left
💡 Hint

Request headers are accessed from pm.request.headers.

🔧 Debug
advanced
2:00remaining
Why does this Postman test fail to detect missing API key?

Here is a Postman test script snippet:

pm.test('API key present', function() {
    pm.expect(pm.request.headers.get('X-API-Key')).to.not.be.undefined;
});

But the test passes even when the API key header is missing. Why?

Apm.request.headers.get throws an error if header is missing
Bpm.request.headers.get returns null, not undefined, when header is missing
Cpm.expect cannot check undefined values
DThe header name is case-sensitive and should be lowercase
Attempts:
2 left
💡 Hint

Check what value pm.request.headers.get returns if header is absent.

framework
expert
2:00remaining
Which Postman pre-request script correctly sets API key header from environment variable?

You want to add an API key stored in the environment variable API_KEY to the request header X-API-Key before sending the request. Which script does this correctly?

Apm.request.headers.upsert({key: 'X-API-Key', value: pm.environment.get('API_KEY')});
Bpm.request.headers.set('X-API-Key', pm.environment.get('API_KEY'));
Cpm.request.headers.add({key: 'X-API-Key', value: pm.environment.get('API_KEY')});
Dpm.request.headers.append({key: 'X-API-Key', value: pm.environment.get('API_KEY')});
Attempts:
2 left
💡 Hint

Use the method that adds or updates a header correctly in Postman scripts.