0
0
Postmantesting~10 mins

Why body format matches API expectations in Postman - Test Your Understanding

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

Complete the code to set the correct Content-Type header for JSON body in Postman.

Postman
pm.request.headers.add({ key: 'Content-Type', value: '[1]' });
Drag options to blanks, or click blank then click option'
Atext/plain
Bmultipart/form-data
Capplication/xml
Dapplication/json
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text/plain' or 'application/xml' causes the API to reject the request.
Omitting the Content-Type header leads to unexpected errors.
2fill in blank
medium

Complete the code to parse the JSON response body in Postman test script.

Postman
const responseData = pm.response.json();
const userId = responseData.[1];
Drag options to blanks, or click blank then click option'
Aid
Bstatus
Cmessage
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' or 'error' fields instead of the user ID.
Trying to access fields that don't exist in the response.
3fill in blank
hard

Fix the error in the test script to correctly check if the response body matches expected JSON format.

Postman
pm.test('Response has valid JSON', function () {
    pm.expect(pm.response.[1]()).to.be.an('object');
});
Drag options to blanks, or click blank then click option'
Atext
Bbody
Cjson
Dhtml
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.text() returns a string, not a JSON object.
Using pm.response.html() is for HTML content, not JSON.
4fill in blank
hard

Fill both blanks to correctly set a JSON body and send the request in Postman pre-request script.

Postman
pm.request.body.raw = JSON.stringify({ [1]: 'John', [2]: 30 });
Drag options to blanks, or click blank then click option'
Aname
Bage
Cusername
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names like 'username' or 'email' when the API expects 'name' and 'age'.
Not stringifying the JSON object before assigning to raw body.
5fill in blank
hard

Fill all three blanks to write a test that asserts the response JSON has a 'success' field true and a 'data' object.

Postman
pm.test('Response success and data check', function () {
    const jsonData = pm.response.[1]();
    pm.expect(jsonData.[2]).to.eql(true);
    pm.expect(jsonData.[3]).to.be.an('object');
});
Drag options to blanks, or click blank then click option'
Ajson
Bsuccess
Cdata
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.text() instead of pm.response.json().
Checking wrong fields like 'status' instead of 'success' or 'data'.
Not verifying the type of 'data' as an object.