Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a query parameter named 'user' with value '123' in Postman.
Postman
pm.request.url.addQueryParams({ user: [1] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the key instead of the value for the parameter.
Forgetting to put quotes around the value.
✗ Incorrect
The value of the query parameter 'user' should be '123', so we put '123' as the value.
2fill in blank
mediumComplete the code to retrieve the value of the query parameter 'page' from the request URL in Postman.
Postman
const page = pm.request.url.query.get([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong key name that does not exist in the query parameters.
Not using quotes around the key name.
✗ Incorrect
To get the value of the 'page' query parameter, we pass 'page' as the key to the get() method.
3fill in blank
hardFix the error in the code to correctly add a query parameter in Postman.
Postman
pm.request.url.query.add({ key: 'sort', value: [1] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the value without quotes causing a syntax error.
Using the key name as the value.
✗ Incorrect
The value must be a string, so it needs to be in quotes: 'desc'.
4fill in blank
hardFill both blanks to create a query parameter object with key 'filter' and value 'active' in Postman.
Postman
const param = { key: [1], value: [2] }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and value.
Forgetting quotes around strings.
✗ Incorrect
The key should be 'filter' and the value should be 'active' as strings.
5fill in blank
hardFill all three blanks to create a query parameter object with key 'category', value 'books', and add it to the request URL in Postman.
Postman
const param = { key: [1], value: [2] };
pm.request.url.query.add([3]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of the param object when adding.
Missing quotes around key or value.
✗ Incorrect
The key is 'category', the value is 'books', and the object param is added to the query parameters.