Hi there,
I’m building a mock API in Postman with requests and example responses for each.
I’d like to use variables in the example body response but they are not working as expected.
I have the following code in the Pre-request Script:
pm.globals.set("v1", "1");
console.log(pm.globals.get("v1"))
pm.collectionVariables.set("v2", "2");
console.log(pm.collectionVariables.get("v2"))
pm.environment.set("v3", "3");
console.log(pm.environment.get("v3"))
pm.variables.set("v4", "4");
console.log(pm.variables.get("v4"))
And then the example body is:
{
"1": "{{v1}}",
"2": "{{v2}}",
"3": "{{v3}}",
"4": "{{v4}}"
}
Only v3 is actually being replaced with a value, however the value being printed is the “Initial Value” of the environmental variable instead of the “Current Value” (that is being updated by the pre-request script).
(This is a shared workspace so there is no auto-persist of variables)
How can I get the current value of the environmental variable in the response body of an example instead of the initla value?