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: