Complete the code to save the response body as a variable in Postman.
pm.test('Save response body', function() { var responseBody = pm.response.[1]; pm.environment.set('responseData', responseBody); });
Use pm.response.text() to get the response body as plain text for saving.
Complete the code to save a JSON field from the response into an environment variable.
pm.test('Save user id', function() { var jsonData = pm.response.[1]; pm.environment.set('userId', jsonData.id); });
Use pm.response.json() to parse the response body as JSON and access fields.
Fix the error in the code to correctly save the response header value.
pm.test('Save content-type header', function() { var contentType = pm.response.headers.get([1]); pm.environment.set('contentType', contentType); });
The header name must be a string with correct casing: 'Content-Type'.
Fill both blanks to save a nested JSON field from the response into a variable.
pm.test('Save nested field', function() { var jsonData = pm.response.[1]; pm.environment.set('city', jsonData.address[2]); });
Parse the response as JSON and access the nested field with dot notation.
Fill all three blanks to save multiple fields from the response into environment variables.
pm.test('Save multiple fields', function() { var data = pm.response.[1]; pm.environment.set('name', data[2]); pm.environment.set('age', data[3]); });
Parse the response as JSON and access each field with dot notation to save them.