Complete the code to extract the token from the first response.
var token = pm.response.json().[1];The token is usually found in the JSON response body under the key access_token. Using pm.response.json().access_token extracts it correctly.
Complete the code to set the extracted token as an environment variable.
pm.environment.set('authToken', [1]);
After extracting the token into the variable token, you set it as an environment variable by passing the variable name directly.
Fix the error in the code to use the environment variable in the next request header.
pm.request.headers.add({ key: 'Authorization', value: 'Bearer ' + [1] });{{authToken}} inside script strings, which doesn't get resolved.In Postman pre-request scripts, retrieve the environment variable using pm.environment.get('authToken') and concatenate it to the Bearer prefix.
Fill both blanks to correctly extract user ID and set it as a global variable.
var userId = pm.response.json().[1]; pm.globals.set('[2]', userId);
The user ID is typically under the key id inside the JSON response. Then, you set it as a global variable named userId for use in other requests.
Fill all three blanks to create a test that checks if the response status is 200 and the token exists.
pm.test('Status code is 200', function () { pm.response.to.have.status([1]); }); pm.test('Token is present', function () { pm.expect(pm.response.json().[2]).to.exist; pm.environment.set('token', pm.response.json().[3]); });
The first test checks if the status code is 200. The second test verifies that the access_token exists in the response JSON and sets it as an environment variable.