0
0
Postmantesting~10 mins

Conditional request execution (setNextRequest) 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 set the next request to 'Login' if the status code is 401.

Postman
if (pm.response.code === [1]) {
    postman.setNextRequest('Login');
}
Drag options to blanks, or click blank then click option'
A500
B200
C401
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 instead of 401 will not trigger the login request.
Using 404 or 500 are incorrect status codes for this condition.
2fill in blank
medium

Complete the code to skip the next request by setting it to null when the response has status 204.

Postman
if (pm.response.code === [1]) {
    postman.setNextRequest(null);
}
Drag options to blanks, or click blank then click option'
A204
B400
C302
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 or 500 will not correctly skip the next request.
Using 302 is a redirect status, not related to skipping requests.
3fill in blank
hard

Fix the error in the code to correctly set the next request to 'GetUser' if the response JSON has 'userId' equal to 123.

Postman
let jsonData = pm.response.json();
if (jsonData.userId [1] 123) {
    postman.setNextRequest('GetUser');
}
Drag options to blanks, or click blank then click option'
A!=
B=
C==
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' causes assignment instead of comparison.
Using '==' allows type coercion which can cause unexpected results.
4fill in blank
hard

Fill both blanks to set the next request to 'Retry' if the response status is 500 and the retry count is less than 3.

Postman
let retryCount = pm.variables.get('[1]') || 0;
if (pm.response.code === 500 && retryCount [2] 3) {
    postman.setNextRequest('Retry');
}
Drag options to blanks, or click blank then click option'
AretryCount
B>
C<
DerrorCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' reverses the logic.
Using 'errorCount' instead of 'retryCount' will cause undefined variable errors.
5fill in blank
hard

Fill all three blanks to set the next request to 'Success' if the response code is 200 and the JSON field 'status' equals 'ok', otherwise set it to 'Failure'.

Postman
let data = pm.response.json();
if (pm.response.code === [1] && data.status [2] [3]) {
    postman.setNextRequest('Success');
} else {
    postman.setNextRequest('Failure');
}
Drag options to blanks, or click blank then click option'
A201
B200
C===
D'ok'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 201 instead of 200 will fail the condition.
Using '==' instead of '===' may cause unexpected type coercion.
Not quoting 'ok' will cause a reference error.