I am getting an error when trying to run my auth scripts (from ping) on anything but my local computer. These test run fine when I am running it through collections on my local computer but fail when trying to run them in the webversion. They also fail with when a teammate is trying to run the collection and when trying to run it through monitors.
TypeError: Parameter 'url' must be a string, not undefined
I am getting this error on my auth API from ping. Here is the first part of the script, it never gets the the second console log because url is undefined despite the require(âurlâ); at the top
This is my code under Test.
const url = require('url');
const querystring = require('querystring');
console.log("lets see if any variables are working: ", pm.environment.get("SEAH 1"));
pm.test("Status code is 302", function () {
pm.response.to.have.status(302);
});
console.log("lets see if Location hearder and URL parse loads: ", url.parse(pm.response.headers.get("Location")));
const loc = url.parse(pm.response.headers.get("Location"));
var params = {};
if (loc.hash) {
params = querystring.parse(loc.hash.substring(1));
} else {
params = querystring.parse(loc.query);
}
I donât remember if I changed a settings to enable this to work but I am not sure why the require(âurlâ) would fail like this.
Thanks I have now SOLVED the issue. I can also trouble shoot it by running it through the web version because it fails for me there too.
Youâre right that it isnât related to the url. It looks like pm.response.headers.get(âLocationâ) is for some reason failing to grab the appropriate header
I changed my code to look at all the response headers
Here is the Location header if i print it out that way.
For Ping to get the authentication flow, just need to disable âAutomatically follow redirectsâ setting. The Ping request will redirect to the next flow, which the test script is not expecting. Disabling auto follow, will present the url parameter that the test script is expecting.