0
0
Postmantesting~10 mins

Body validation before sending 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 check if the request body is not empty before sending.

Postman
if ([1]) {
  pm.sendRequest(request, callback);
}
Drag options to blanks, or click blank then click option'
Apm.request.body.text
Bpm.request.body
Cpm.request.body.raw
Dpm.request.body.json
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.request.body.json which is undefined in this context.
Checking pm.request.body without accessing raw content.
Using pm.request.body.text which is not a valid property.
2fill in blank
medium

Complete the code to validate that the JSON body contains a 'name' field before sending.

Postman
const body = JSON.parse(pm.request.body.raw);
if (body.[1]) {
  pm.sendRequest(request, callback);
}
Drag options to blanks, or click blank then click option'
Aid
Bvalue
Cemail
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'id' or 'email' instead of 'name'.
Not parsing the JSON body before accessing fields.
Using incorrect property names.
3fill in blank
hard

Fix the error in the code to correctly validate the body length before sending.

Postman
if (pm.request.body.raw.[1] > 0) {
  pm.sendRequest(request, callback);
}
Drag options to blanks, or click blank then click option'
Alength
Bsize
Ccount
Dlength()
Attempts:
3 left
💡 Hint
Common Mistakes
Using length() which causes a runtime error.
Using size or count which are not valid string properties.
4fill in blank
hard

Fill both blanks to parse the JSON body and check if the 'age' field is greater than 18 before sending.

Postman
const data = JSON.parse(pm.request.body.[1]);
if (data.[2] > 18) {
  pm.sendRequest(request, callback);
}
Drag options to blanks, or click blank then click option'
Araw
Btext
Cage
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.request.body.text which is not a valid property.
Checking a wrong field like 'value' instead of 'age'.
5fill in blank
hard

Fill all three blanks to create a validation that sends the request only if the body has a 'status' field equal to 'active'.

Postman
const body = JSON.parse(pm.request.body.[1]);
if (body.[2] === [3]) {
  pm.sendRequest(request, callback);
}
Drag options to blanks, or click blank then click option'
Araw
Bstatus
C"active"
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.request.body.text which is invalid.
Comparing to 'active' without quotes causing syntax errors.
Checking wrong field names.