I have Get request which gives me response like below
{
"var1": "value1",
"var2": "value2"
}
I am saving it in an environment variable from Tests script as below
postman.setEnvironmentVariable("allData", JSON.stringify(responseBody));
In next Post request, I am trying to retrieve above values from Pre-request script as below
var jsonData = JSON.parse(allData)
However I am getting not defined error as below
There was an error in evaluating the Pre-request Script: ReferenceError: allData is not defined
I can set each property in an individual variable and that works fine but that pollutes environment (as there are around 20 such properties). Please suggest better alternate for the same. Also suggest me how to access individual values in Body of the Post request. Can I do something like below?
{
"var1": "{{jsonData.var1}}",
"var2": "{{jsonData.var2}}"
}
OR I need to set values to individual variable in Pre-request script and use them in Body?
Thanks
pm.environment.get("variable_key");to get the environment variable. - junkangli