Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to extract the token from the response and save it as an environment variable.
Postman
pm.environment.set('authToken', pm.response.json().[1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect key names like 'status' or 'message' instead of 'token'.
Not using pm.response.json() to parse the response.
✗ Incorrect
The token is usually stored in the 'token' field of the JSON response. We extract it using pm.response.json().token and save it as 'authToken'.
2fill in blank
mediumComplete the code to use the extracted token in the Authorization header of the next request.
Postman
pm.request.headers.add({ key: 'Authorization', value: 'Bearer ' + pm.environment.get('[1]') }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that was not set previously.
Forgetting to add 'Bearer ' before the token.
✗ Incorrect
We use the environment variable 'authToken' that was set earlier to pass the token in the Authorization header.
3fill in blank
hardFix the error in the test script to correctly extract the user ID from the response and save it.
Postman
let userId = pm.response.json().[1]; pm.environment.set('userId', userId);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user_id' or 'userid' which may not exist in the response.
Using wrong case like 'userId' if the response uses 'id'.
✗ Incorrect
The correct key for user ID in the response JSON is 'id'. Using 'id' extracts the user ID properly.
4fill in blank
hardFill both blanks to create a test that checks if the extracted token is not empty and saves it.
Postman
let token = pm.response.json().[1]; if (token [2] '') { pm.environment.set('authToken', token); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!==' causing wrong condition.
Using wrong key name like 'accessToken' if the response uses 'token'.
✗ Incorrect
We extract 'token' from the response and check if it is not equal to an empty string before saving it.
5fill in blank
hardFill all three blanks to extract 'id' and 'name' from the response and save them as environment variables if 'id' is greater than 0.
Postman
let data = pm.response.json(); let userId = data.[1]; let userName = data.[2]; if (userId [3] 0) { pm.environment.set('userId', userId); pm.environment.set('userName', userName); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'userId' or 'userName' if response uses 'id' and 'name'.
Using '<' instead of '>' causing wrong condition.
✗ Incorrect
We extract 'id' and 'name' from the response JSON. Then we check if 'id' is greater than 0 before saving both variables.