0
0
Postmantesting~20 mins

Dynamic URL building in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dynamic URL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Dynamic URL Variables in Postman

In Postman, you want to create a dynamic URL that changes based on environment variables. Which of the following URL formats correctly uses environment variables to build a dynamic URL?

Ahttps://{{baseUrl}}/api/{{version}}/users
Bhttps://baseUrl/api/version/users
Chttps://${baseUrl}/api/${version}/users
Dhttps://[baseUrl]/api/[version]/users
Attempts:
2 left
💡 Hint

Postman uses double curly braces to reference variables in URLs.

Predict Output
intermediate
2:00remaining
Output of URL Construction with Pre-request Script

Given the following Postman pre-request script, what will be the final URL used in the request if the environment variable userId is set to 42?

pm.environment.set('userId', '42');
pm.variables.set('endpoint', `/users/${pm.environment.get('userId')}`);

The request URL is set as: https://api.example.com{{endpoint}}

Ahttps://api.example.com/users/42
Bhttps://api.example.com/users/${userId}
Chttps://api.example.com{{endpoint}}
Dhttps://api.example.com/users/pm.environment.get('userId')
Attempts:
2 left
💡 Hint

Variables set with pm.variables.set can be used with double curly braces in the URL.

assertion
advanced
2:00remaining
Validating Dynamic URL Components in Tests

You want to write a test in Postman to check that the request URL contains the correct user ID dynamically. Which assertion correctly verifies that the URL includes the user ID stored in the environment variable userId?

Postman
const userId = pm.environment.get('userId');
const url = pm.request.url.toString();
Apm.test('URL contains userId', () => pm.expect(url).to.equal(userId));
Bpm.test('URL contains userId', () => pm.expect(url).to.include(userId));
Cpm.test('URL contains userId', () => pm.expect(url).to.have.property(userId));
Dpm.test('URL contains userId', () => pm.expect(url).to.be.true(userId));
Attempts:
2 left
💡 Hint

Check if the URL string includes the userId substring.

🔧 Debug
advanced
2:00remaining
Debugging Incorrect URL Variable Substitution

In Postman, the request URL is set as https://api.example.com/{{endpoint}}. The pre-request script sets pm.environment.set('endpoint', '/users/123'). However, the request is sent to https://api.example.com/%7B%7Bendpoint%7D%7D instead of https://api.example.com/users/123. What is the most likely cause?

AThe URL should use single curly braces instead of double curly braces for variables.
BThe variable <code>endpoint</code> is set using pm.environment.set but should use pm.variables.set.
CThe variable <code>endpoint</code> is set in environment but the active environment is not selected.
DThe variable <code>endpoint</code> contains invalid characters that prevent substitution.
Attempts:
2 left
💡 Hint

Check if the environment with the variable is active in Postman.

framework
expert
3:00remaining
Best Practice for Dynamic URL Building in Postman Collections

When designing a Postman collection to test multiple API versions dynamically, which approach best supports maintainability and flexibility for dynamic URL building?

AUse pre-request scripts to concatenate strings and set the full URL dynamically for each request.
BHardcode the full URL in each request and duplicate requests for each API version.
CUse global variables for all URL parts and update them manually before each run.
DUse environment variables for base URL and API version, and reference them in the request URLs with {{baseUrl}} and {{apiVersion}}.
Attempts:
2 left
💡 Hint

Consider ease of updating and reusability across requests.