Repository navigation
Evaluating merged variables in pre-request script #9598
|
Consider this scenario: Base Environment: Selecting Sub-Environment as current environment, I can use {{apuUrl}} and it correctly revaluates to http://www.example.com/api However, in the pre-requestr script there is no proper function to return the evaluated/merged variable value. That would be great in the script to evaluate the correct value of the variable based on selected environment. |
Replies: 1 comment
|
Hi @rmeshksar there's a roundabout way to accomplish what you're looking for. You can loop until all variables have been resolved/replaced by manually invoking the console.log(insomnia.variables.toObject());
let apiUrl = '{{apiUrl}}';
while (apiUrl.includes('{{')) {
try {
apiUrl = insomnia.variables.replaceIn(apiUrl);
} catch (e) {
console.error("could not resolve a variable in template", apiUrl);
break;
}
}
console.log(apiUrl);
|

Hi @rmeshksar there's a roundabout way to accomplish what you're looking for. You can loop until all variables have been resolved/replaced by manually invoking the
replaceInmethod: