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?
Remember that Postman uses a specific order to resolve variables, and environment variables have a higher priority than collection variables.
Postman resolves variables by checking environment variables before collection variables. So if a variable exists in both scopes, the environment variable value is used.
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?
Check how pm.variables.get resolves variables from different scopes.
pm.variables.get looks through all variable scopes including collection variables, so it finds the token set in collection variables and returns xyz123.
Which of the following Postman scripts correctly sets a collection variable named userId to the value 789?
Remember the method signature for setting collection variables requires a string key and a value.
The correct syntax uses pm.collectionVariables.set('key', value). Option D follows this exactly.
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?
Consider code readability and maintainability when updating multiple variables.
Option A is efficient and clean: it uses a loop to set multiple variables, avoiding repetitive code and ensuring correctness.
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?
Think about how Postman handles variable persistence and saving collections.
Collection variables set during runtime are saved in memory but not persisted to disk unless you save the collection manually. This is why the variable disappears after the request.