0
0
Postmantesting~10 mins

Setting variables in scripts 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 a global variable named 'token' with value 'abc123'.

Postman
pm.globals.set('token', [1]);
Drag options to blanks, or click blank then click option'
A"token"
Babc123
Ctoken
D'abc123'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string value.
Using variable names instead of string literals.
2fill in blank
medium

Complete the code to set an environment variable 'userId' to the value of a response JSON field 'id'.

Postman
pm.environment.set('userId', pm.response.json().[1]);
Drag options to blanks, or click blank then click option'
AuserId
Bid
Cuser_id
DID
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names or wrong case.
Using quotes around the field name inside the JSON accessor.
3fill in blank
hard

Fix the error in the code to correctly set a collection variable 'session' to 'active'.

Postman
pm.collectionVariables.set([1], 'active');
Drag options to blanks, or click blank then click option'
A'session'
Bsession
C"session"
Dactive
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variable name without quotes causes a ReferenceError.
Confusing variable name with variable value.
4fill in blank
hard

Fill both blanks to set a global variable 'count' to the length of an array 'items' from the response JSON.

Postman
pm.globals.set([1], pm.response.json().[2].length);
Drag options to blanks, or click blank then click option'
A'count'
Bitems
C'items'
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around JSON field names in dot notation.
Not quoting the variable name string.
5fill in blank
hard

Fill all three blanks to set an environment variable 'status' to 'success' only if the response JSON field 'code' equals 200.

Postman
if (pm.response.json().[1] === [2]) {
  pm.environment.set([3], 'success');
}
Drag options to blanks, or click blank then click option'
Acode
B200
C'status'
D'code'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around JSON field name in dot notation.
Using quotes around the number 200.
Not quoting the variable name string.