Complete the code to set a global variable named 'token' with value 'abc123'.
pm.globals.set('token', [1]);
The pm.globals.set function requires the value to be a string, so it must be enclosed in quotes.
Complete the code to set an environment variable 'userId' to the value of a response JSON field 'id'.
pm.environment.set('userId', pm.response.json().[1]);
The response JSON field is named 'id', so we access it with pm.response.json().id.
Fix the error in the code to correctly set a collection variable 'session' to 'active'.
pm.collectionVariables.set([1], 'active');
The variable name must be a string, so it needs quotes around it.
Fill both blanks to set a global variable 'count' to the length of an array 'items' from the response JSON.
pm.globals.set([1], pm.response.json().[2].length);
The variable name 'count' must be a string, so it needs quotes. The array is named 'items' in the JSON, accessed without quotes.
Fill all three blanks to set an environment variable 'status' to 'success' only if the response JSON field 'code' equals 200.
if (pm.response.json().[1] === [2]) { pm.environment.set([3], 'success'); }
We check if the JSON field 'code' equals the number 200, then set the environment variable 'status' (string) to 'success'.