Complete the code to add an Authorization header in Postman.
pm.request.headers.add({key: 'Authorization', value: '[1]'});The Authorization header with a Bearer token is required to authenticate API requests securely.
Complete the test script to check if the response status code is 401 for unauthorized access.
pm.test('Unauthorized status code', function () { pm.response.to.have.status([1]); });
Status code 401 means unauthorized access, which is expected when auth fails.
Fix the error in the test script to verify the presence of a token in the response JSON.
pm.test('Token is present', function () { pm.expect(pm.response.json().[1]).to.exist; });
The 'access_token' field holds the token needed for authenticated API calls.
Fill both blanks to create a test that checks if the response JSON has a user ID and the status is 'success'.
pm.test('Response has user ID and success status', function () { pm.expect(pm.response.json().[1]).to.be.a('string'); pm.expect(pm.response.json().status).to.eql('[2]'); });
The user ID is usually under 'user_id' and the status should be 'success' for a valid response.
Fill all three blanks to write a test that verifies the token type, token expiration, and that the token is a non-empty string.
pm.test('Token details are valid', function () { const jsonData = pm.response.json(); pm.expect(jsonData.token_type).to.eql('[1]'); pm.expect(jsonData.expires_in).to.be.above([2]); pm.expect(jsonData.access_token).to.be.a('[3]').and.not.empty; });
The token type should be 'Bearer', expiration time should be greater than 0, and the access token must be a non-empty string.