Getting TypeError: Parameter 'url' must be a string, not undefined. When trying to run in monitor or when teammates try to run the tests

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.

I suspect the issue is not with the command but the data\string its trying to parse.

Pretty sure its just telling you that there is no data to be parsed.

Why is it working for you locally, but not your colleague. Don’t know without knowing a lot more about your setup.

Therefore I guess you need to troubleshoot on a colleagues machine to start with.

First I would check that the response is coming back ok. That it has the appropriate location headers.

Then I would be checking that your colleagues are getting the Location URL returned to them.

pm.response.headers.get("Location")

I would recommend defining the location in a separate variable, and then url.parsing afterwards.

This way, you can narrow down which bit of code is causing the issue. Suspect its the variable, not the url.parse command.

Is the location being returned, is it an absolute URL (starting with http) or a relative URL (/index.html) which I would expect to fail.

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
image

Here is the Location header if i print it out that way.

Now I set the location variable first, then I use url.parse and it works great.
image

Still really odd that it would pass on my local. but fail on the web version or on my colleagues machine.

1 Like

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.