Bird
Raised Fist0
Postmantesting~20 mins

Dynamic URL building in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main purpose of using dynamic URL building in Postman?
easy
A. To make URLs longer and more complex
B. To write URLs only once without any changes
C. To reuse URLs by inserting variables for flexibility
D. To avoid using variables in requests

Solution

  1. Step 1: Understand dynamic URL building

    Dynamic URL building means using variables to create flexible URLs that can change based on input.
  2. Step 2: Identify the benefit in Postman

    Using variables like {{variableName}} lets you reuse URLs easily without rewriting them for each test.
  3. Final Answer:

    To reuse URLs by inserting variables for flexibility -> Option C
  4. Quick Check:

    Dynamic URL building = reuse URLs with variables [OK]
Hint: Remember: variables make URLs flexible and reusable [OK]
Common Mistakes:
  • Thinking dynamic URLs make URLs longer
  • Believing variables are not needed in URLs
  • Confusing dynamic URLs with static URLs
2. Which of the following is the correct syntax to use a variable named userId in a Postman URL?
easy
A. /api/users/%userId%
B. /api/users/$userId
C. /api/users/{userId}
D. /api/users/{{userId}}

Solution

  1. Step 1: Recall Postman variable syntax

    Postman uses double curly braces {{variableName}} to insert variables in URLs.
  2. Step 2: Match syntax to options

    Only /api/users/{{userId}} uses {{userId}}, which is the correct Postman syntax.
  3. Final Answer:

    /api/users/{{userId}} -> Option D
  4. Quick Check:

    Postman variable syntax = {{variableName}} [OK]
Hint: Use double curly braces {{}} for variables in Postman URLs [OK]
Common Mistakes:
  • Using single braces or dollar signs instead of {{}}
  • Confusing Postman syntax with other languages
  • Forgetting to wrap variable names in curly braces
3. Given the environment variable baseUrl set to https://api.example.com and the request URL {{baseUrl}}/users/{{userId}} with userId set to 42, what is the final URL sent by Postman?
medium
A. https://api.example.com/users/42
B. https://api.example.com/users/{{userId}}
C. {{baseUrl}}/users/42
D. https://api.example.com/users/

Solution

  1. Step 1: Substitute environment variables

    Postman replaces {{baseUrl}} with its value https://api.example.com and {{userId}} with 42.
  2. Step 2: Build the final URL

    After substitution, the URL becomes https://api.example.com/users/42.
  3. Final Answer:

    https://api.example.com/users/42 -> Option A
  4. Quick Check:

    Variable substitution = final URL with values [OK]
Hint: Replace all {{variables}} with their values before sending [OK]
Common Mistakes:
  • Leaving variables unsubstituted in the URL
  • Mixing variable names or values
  • Ignoring environment variable settings
4. You wrote the URL {{baseUrl}/users/{{userId}} in Postman, but the request fails. What is the likely error?
medium
A. Missing closing curly brace for {{baseUrl}} variable
B. Using wrong variable name userId
C. Variables cannot be used in URLs
D. Postman does not support dynamic URLs

Solution

  1. Step 1: Check variable syntax carefully

    The URL has {{baseUrl} missing a closing brace, which breaks variable substitution.
  2. Step 2: Understand impact of syntax error

    Without proper braces, Postman cannot replace the variable, causing the request to fail.
  3. Final Answer:

    Missing closing curly brace for {{baseUrl}} variable -> Option A
  4. Quick Check:

    Correct variable syntax requires matching {{ and }} [OK]
Hint: Always count opening and closing braces in variables [OK]
Common Mistakes:
  • Forgetting to close curly braces
  • Assuming variable names are wrong without checking syntax
  • Believing variables can't be used in URLs
5. You want to build a URL in Postman that changes the endpoint based on a variable env which can be dev or prod. Which URL correctly uses dynamic URL building to select the environment?
hard
A. https://api.example.com/env/users
B. https://api.example.com/{{env}}/users
C. https://api.example.com/${env}/users
D. https://api.example.com/{env}/users

Solution

  1. Step 1: Identify correct variable syntax for environment

    Postman uses {{env}} to insert the variable value dynamically in the URL.
  2. Step 2: Confirm URL structure for environment selection

    Using https://api.example.com/{{env}}/users allows switching between dev or prod endpoints easily.
  3. Final Answer:

    https://api.example.com/{{env}}/users -> Option B
  4. Quick Check:

    Use {{variable}} to dynamically select URL parts [OK]
Hint: Use {{env}} to switch URL parts dynamically [OK]
Common Mistakes:
  • Using wrong variable syntax like ${env} or {env}
  • Hardcoding environment names instead of variables
  • Not placing variable in correct URL position