Complete the code to use a variable instead of hardcoding the URL.
pm.sendRequest({ url: [1], method: 'GET' }, function (err, res) { pm.test('Status code is 200', function () { pm.expect(res.code).to.eql(200); }); });Using pm.environment.get('baseUrl') fetches the URL from environment variables, avoiding hardcoding.
Complete the code to set a variable for the API key instead of hardcoding it.
pm.environment.set('apiKey', [1]);
The API key should be set as a string value in environment variables using quotes.
Fix the error in the code to correctly retrieve a variable value.
const token = [1]('authToken');
Use pm.environment.get to retrieve the value of 'authToken' from environment variables.
Fill both blanks to create a request using variables for URL and method.
pm.sendRequest({ url: [1], method: [2] }, function (err, res) { pm.test('Response received', () => { pm.expect(res).to.have.property('code'); }); });The URL is fetched from environment variable 'requestUrl' and method is set to 'GET' as a string.
Fill all three blanks to set variables and use them in a request.
pm.environment.set('userId', [1]); pm.environment.set('authToken', [2]); pm.sendRequest({ url: pm.environment.get('baseUrl') + '/user/' + pm.environment.get([3]), method: 'GET' }, (err, res) => { pm.test('User data fetched', () => { pm.expect(res.code).to.eql(200); }); });
Set 'userId' to '7890', 'authToken' to 'token_abc123', and use 'userId' to get the user ID in the URL.