Complete the code to access an environment variable named 'api_key' in Postman test script.
const apiKey = pm.environment.get('[1]');
In Postman, environment variables are accessed by their exact name using pm.environment.get(). Here, the variable name is 'api_key'.
Complete the code to set an environment variable 'session_id' to '12345' in Postman test script.
pm.environment.[1]('session_id', '12345');
To assign a value to an environment variable in Postman, use pm.environment.set() with the variable name and value.
Fix the error in the code to remove an environment variable named 'token' in Postman test script.
pm.environment.[1]('token');
To remove an environment variable in Postman, use pm.environment.unset() with the variable name.
Fill both blanks to check if environment variable 'user_id' exists and log its value in Postman test script.
if (pm.environment.[1]('user_id')) { console.log(pm.environment.[2]('user_id')); }
Use pm.environment.has() to check if a variable exists, and pm.environment.get() to retrieve its value.
Fill all three blanks to update environment variable 'count' by incrementing its value by 1 in Postman test script.
let count = parseInt(pm.environment.[1]('count') || '0'); count = count [2] 1; pm.environment.[3]('count', count.toString());
First, get the current value with get. Then add 1 using +. Finally, update the variable with set.