0
0
Postmantesting~10 mins

Saving responses in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to save the response body as a variable in Postman.

Postman
pm.test('Save response body', function() {
    var responseBody = pm.response.[1];
    pm.environment.set('responseData', responseBody);
});
Drag options to blanks, or click blank then click option'
Atext()
Bdata()
Cbody()
Djson()
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.json() when the response is not JSON.
Trying to access pm.response.body() which is not a valid method.
2fill in blank
medium

Complete the code to save a JSON field from the response into an environment variable.

Postman
pm.test('Save user id', function() {
    var jsonData = pm.response.[1];
    pm.environment.set('userId', jsonData.id);
});
Drag options to blanks, or click blank then click option'
Atext()
Bdata()
Cbody()
Djson()
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.text() and trying to access JSON fields directly.
Forgetting to parse the response before accessing properties.
3fill in blank
hard

Fix the error in the code to correctly save the response header value.

Postman
pm.test('Save content-type header', function() {
    var contentType = pm.response.headers.get([1]);
    pm.environment.set('contentType', contentType);
});
Drag options to blanks, or click blank then click option'
A'Content-Type'
BContent-Type
C'contenttype'
DcontentType
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the header name.
Using incorrect casing for the header name.
4fill in blank
hard

Fill both blanks to save a nested JSON field from the response into a variable.

Postman
pm.test('Save nested field', function() {
    var jsonData = pm.response.[1];
    pm.environment.set('city', jsonData.address[2]);
});
Drag options to blanks, or click blank then click option'
Ajson()
Btext()
C.city
D['city']
Attempts:
3 left
💡 Hint
Common Mistakes
Using text() instead of json() to parse response.
Using incorrect syntax to access nested fields.
5fill in blank
hard

Fill all three blanks to save multiple fields from the response into environment variables.

Postman
pm.test('Save multiple fields', function() {
    var data = pm.response.[1];
    pm.environment.set('name', data[2]);
    pm.environment.set('age', data[3]);
});
Drag options to blanks, or click blank then click option'
Ajson()
B.name
C.age
Dtext()
Attempts:
3 left
💡 Hint
Common Mistakes
Using text() instead of json() to parse response.
Trying to access fields without parsing JSON.