How do I store that in a variable in the prescript so that I can use it in the test?
For example I tried this but itās not working:
var billerCode = pm.request.url.query.get(ābillerCodeā);
console.log(billerCode);
Itās saying itās undefined.
UPDATE: Itās a path variable not a query param, so the solution was pm.request.url.variables.get(ābillerCodeā);
Thread can be deleted unless you want to keep it around. Thanks.
Hereās an example of how you can extract all of the query parameters from your request (in case you have multiple parameters), and then how you can specifically get to the billerCode:
var query = {};
pm.request.url.query.all().forEach((param) => { query[param.key] = param.value});
var billerCode = query["billerCode"];
Thank you Neil for the response!
I figured out my problem just as you sent that, my variable is a path variable not a query param.
So I needed to do: pm.request.url.variables.get(ābillerCodeā);
I will take your code into my cheat sheet as well. Thanks!
Youāre not doing anything wrong! You canāt directly call pm.request.url.variables from the Tests tab, because by the time this code is executed, the path variables have all been resolved (itās just a single, fully-formed string by this point).
The best way to track the value between the Pre-Request and Tests tab would be to push it through in a temporary local variable, i.e: