0
0
Postmantesting~10 mins

Dynamic URL building 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 insert the base URL variable in the request URL.

Postman
pm.sendRequest(`$[1]/users`, function (err, res) {
    pm.expect(err).to.be.null;
    pm.expect(res).to.have.property('code', 200);
});
Drag options to blanks, or click blank then click option'
Apm.environment.get('baseUrl')
Bpm.variables.get('baseUrl')
Cpm.request.url
Dpm.response.json()
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.variables.get() instead of pm.environment.get() for environment variables.
Using pm.request.url which is the current request URL, not the base URL.
Trying to get the URL from the response.
2fill in blank
medium

Complete the code to build a dynamic URL with a user ID path parameter.

Postman
const userId = pm.environment.get('userId');
const url = `$[1]/users/${userId}`;
pm.sendRequest(url, function (err, res) {
    pm.expect(res).to.have.property('code', 200);
});
Drag options to blanks, or click blank then click option'
Apm.request.url
Bpm.variables.get('userId')
Cpm.response.json()
Dpm.environment.get('baseUrl')
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.variables.get('userId') for the base URL instead of userId variable.
Using pm.request.url which is the current request URL, not the base URL.
Not using template literals correctly.
3fill in blank
hard

Fix the error in the code to correctly append query parameters to the URL.

Postman
const baseUrl = pm.environment.get('baseUrl');
const params = new URLSearchParams();
params.append('status', 'active');
const url = baseUrl + '/users?[1]';
pm.sendRequest(url, function (err, res) {
    pm.expect(res).to.have.property('code', 200);
});
Drag options to blanks, or click blank then click option'
Aparams
Bparams.toString()
Cparams.append()
Dparams.get()
Attempts:
3 left
💡 Hint
Common Mistakes
Appending the params object directly without converting to string.
Using params.append() which adds parameters but does not return a string.
Using params.get() which retrieves a value, not the whole query string.
4fill in blank
hard

Fill both blanks to build a URL with multiple query parameters dynamically.

Postman
const baseUrl = pm.environment.get('baseUrl');
const params = new URLSearchParams();
params.append('status', 'active');
params.append('role', [1]);
const url = baseUrl + '/users?[2]';
pm.sendRequest(url, function (err, res) {
    pm.expect(res).to.have.property('code', 200);
});
Drag options to blanks, or click blank then click option'
A'admin'
Bparams.toString()
Cparams
D'user'
Attempts:
3 left
💡 Hint
Common Mistakes
Using params object directly in the URL without converting to string.
Not quoting the role value string.
Using params instead of params.toString() for the URL.
5fill in blank
hard

Fill all three blanks to build a dynamic URL with path and query parameters.

Postman
const baseUrl = pm.environment.get([1]);
const userId = pm.environment.get('userId');
const params = new URLSearchParams();
params.append('active', [2]);
const url = `${baseUrl}/users/$[3]?${params.toString()}`;
pm.sendRequest(url, function (err, res) {
    pm.expect(res).to.have.property('code', 200);
});
Drag options to blanks, or click blank then click option'
A'baseUrl'
B'true'
CuserId
D'userId'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the environment variable name in get().
Using boolean true instead of string 'true' for query parameter.
Using string 'userId' instead of variable userId for path.