Bird
Raised Fist0
Postmantesting~20 mins

Collection variables in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Collection Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Collection Variable Scope

In Postman, you have a collection variable named api_key set to 12345. You also have an environment variable with the same name api_key set to abcde. When you run a request inside this collection, which api_key value will Postman use?

AThe environment variable value <code>abcde</code> will be used because environment variables have higher priority than collection variables.
BPostman will randomly pick either <code>12345</code> or <code>abcde</code> each time the request runs.
CPostman will throw an error because variables with the same name cannot exist in collection and environment scopes.
DThe collection variable value <code>12345</code> will be used because collection variables override environment variables.
Attempts:
2 left
💡 Hint

Remember that Postman uses a specific order to resolve variables, and environment variables have a higher priority than collection variables.

❓ query_result
intermediate
2:00remaining
Output of Variable Resolution in Pre-request Script

Given the following pre-request script in a Postman collection:

pm.collectionVariables.set('token', 'xyz123');
const tokenValue = pm.variables.get('token');
console.log(tokenValue);

What will be printed in the Postman console when this script runs?

Anull
Bundefined
Cxyz123
DAn error is thrown because <code>pm.variables.get</code> cannot access collection variables.
Attempts:
2 left
💡 Hint

Check how pm.variables.get resolves variables from different scopes.

📝 Syntax
advanced
2:00remaining
Correct Syntax to Set a Collection Variable

Which of the following Postman scripts correctly sets a collection variable named userId to the value 789?

Apm.collectionVariables['userId'] = 789;
Bpm.collectionVariables.set(userId, '789');
Cpm.collectionVariables.set('userId' = '789');
Dpm.collectionVariables.set('userId', 789);
Attempts:
2 left
💡 Hint

Remember the method signature for setting collection variables requires a string key and a value.

❓ optimization
advanced
2:00remaining
Efficiently Updating Multiple Collection Variables

You want to update three collection variables var1, var2, and var3 with new values 10, 20, and 30 respectively in a pre-request script. Which approach is the most efficient and correct?

ACreate an object with all variables and use a loop to set each variable with <code>pm.collectionVariables.set</code>.
BSet variables directly on <code>pm.collectionVariables</code> like properties, e.g., <code>pm.collectionVariables.var1 = 10</code>.
CUse <code>pm.collectionVariables.set</code> once with all variables as an object argument.
DCall <code>pm.collectionVariables.set</code> three times, once for each variable.
Attempts:
2 left
💡 Hint

Consider code readability and maintainability when updating multiple variables.

🔧 Debug
expert
2:00remaining
Debugging Collection Variable Persistence Issue

You set a collection variable sessionId in a test script using pm.collectionVariables.set('sessionId', 'abc123');. However, after the request finishes, the variable sessionId is not saved and disappears. What is the most likely reason?

AThe collection variable name <code>sessionId</code> is reserved and cannot be used.
BCollection variables set in test scripts are not saved persistently unless you explicitly save the collection.
CYou must use <code>pm.variables.set</code> instead of <code>pm.collectionVariables.set</code> to persist variables.
DCollection variables set in scripts are saved only if the Postman app is running in offline mode.
Attempts:
2 left
💡 Hint

Think about how Postman handles variable persistence and saving collections.

Practice

(1/5)
1. What is the main purpose of collection variables in Postman?
easy
A. To store reusable values accessible by all requests in a collection
B. To store environment-specific URLs only
C. To save responses from API calls automatically
D. To create user interface themes in Postman

Solution

  1. Step 1: Understand what collection variables do

    Collection variables hold values that can be reused across all requests in a collection, making tests easier to manage.
  2. Step 2: Compare options with this purpose

    Only To store reusable values accessible by all requests in a collection describes storing reusable values for all requests, which matches the purpose of collection variables.
  3. Final Answer:

    To store reusable values accessible by all requests in a collection -> Option A
  4. Quick Check:

    Collection variables = reusable values [OK]
Hint: Remember: collection variables share values across all collection requests [OK]
Common Mistakes:
  • Confusing collection variables with environment variables
  • Thinking collection variables store API responses
  • Assuming collection variables control UI settings
2. Which syntax correctly uses a collection variable named api_key inside a request URL in Postman?
easy
A. https://api.example.com/data?key=api_key
B. https://api.example.com/data?key=[api_key]
C. https://api.example.com/data?key=$api_key
D. https://api.example.com/data?key={{api_key}}

Solution

  1. Step 1: Recall Postman variable syntax

    Postman uses double curly braces {{variable_name}} to insert variables into requests.
  2. Step 2: Match syntax with options

    Only https://api.example.com/data?key={{api_key}} uses {{api_key}}, which is the correct way to reference a collection variable.
  3. Final Answer:

    https://api.example.com/data?key={{api_key}} -> Option D
  4. Quick Check:

    Variable syntax = {{variable_name}} [OK]
Hint: Use double curly braces {{}} to insert variables in Postman [OK]
Common Mistakes:
  • Using plain variable name without braces
  • Using square brackets or dollar sign instead of {{}}
  • Confusing environment and collection variable syntax
3. Given a collection variable base_url set to https://api.test.com, what will be the full URL for this request?
GET {{base_url}}/users
medium
A. GET https://api.test.com/users
B. GET {{base_url}}/users
C. GET https://api.test.com{{base_url}}/users
D. GET /users

Solution

  1. Step 1: Substitute the collection variable

    The variable {{base_url}} is replaced by its value https://api.test.com in the request URL.
  2. Step 2: Combine the parts of the URL

    After substitution, the URL becomes https://api.test.com/users as the path /users is appended.
  3. Final Answer:

    GET https://api.test.com/users -> Option A
  4. Quick Check:

    Variable replaced by value = full URL [OK]
Hint: Replace {{variable}} with its value to get the full URL [OK]
Common Mistakes:
  • Not replacing the variable and leaving {{base_url}} as is
  • Appending variable value incorrectly
  • Ignoring the path after the variable
4. You set a collection variable token but your request still sends Authorization: Bearer {{token}} literally without replacing it. What is the likely cause?
medium
A. You used single curly braces instead of double
B. The collection variable token was not saved properly
C. Postman does not support collection variables in headers
D. The variable name is case-insensitive and mismatched

Solution

  1. Step 1: Understand variable replacement behavior

    If Postman sends {{token}} literally, it means the variable was not found or set correctly.
  2. Step 2: Identify common causes

    Most often, the variable was not saved or defined in the collection variables, so Postman cannot replace it.
  3. Final Answer:

    The collection variable token was not saved properly -> Option B
  4. Quick Check:

    Missing variable value = no replacement [OK]
Hint: Check if collection variable is saved before using it [OK]
Common Mistakes:
  • Assuming single braces work for variables
  • Thinking headers can't use variables
  • Ignoring case sensitivity issues
5. You want to use a collection variable user_id in a request body JSON like this:
{ "id": "{{user_id}}", "action": "delete" }

But the API expects id as a number, not a string. How should you fix the request body to send user_id as a number?
hard
A. { "id": "{{user_id}}", "action": "delete" }
B. { "id": '${{user_id}}', "action": "delete" }
C. { "id": {{user_id}}, "action": "delete" }
D. { "id": [{{user_id}}], "action": "delete" }

Solution

  1. Step 1: Understand JSON data types

    In JSON, numbers should not be inside quotes; quotes make them strings.
  2. Step 2: Adjust variable usage in JSON

    Remove quotes around {{user_id}} so Postman inserts the number directly, matching API expectation.
  3. Final Answer:

    { "id": {{user_id}}, "action": "delete" } -> Option C
  4. Quick Check:

    Numbers in JSON = no quotes [OK]
Hint: Remove quotes around {{variable}} to send numbers, not strings [OK]
Common Mistakes:
  • Keeping quotes around numeric variables
  • Using wrong variable syntax with $ or []
  • Sending arrays instead of single values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard