Getting 401 Error when using env variables or pm.request.url, but works if Path Variable is set under Params or url is hardcoded

I’m trying to send a GET Request that will eventually iterate over a list of numbers, but debugging has led me to find that I receive a 401 error anytime I attempt to use variables in the URL. I have tried environment variables, local variables, collection variables, and just setting the url through pm.request.url, but all return 401 errors. I can see in the console that my Authentication header appears to be correct.

Running the request using Path Variables under Params or hardcoding the id at the end returns 200

I’m not seeing a difference between the two requests.

The URL is being overwritten in both requests. Via the pm.request.url line.

Without seeing more of the request. How you are setting the authentication, plus the full console logs for both requests. It will be hard to troubleshoot here.

I can only suggest looking at the console logs carefully for both the passing and failing request. To see if you can spot any differences.

What I can see though is a space before the variable in the first screenshot (although it shouldn’t really matter as you are overwriting the whole URL in the pre-request script).

Ah apologies for confusion, I have to comment out the pm.request.url line when manually inputting the id into the GET request for it to return 200. I get a 401 if I overwrite the url or use a variable in the url.

There isn’t a space before the variable in the first screenshot, it just appears that way.

The authentication is being set in the Collection pre-request using pm.request.headers.add({ key: ‘Authorization’, value: authHeaderFull });

The console logs look identical (outside of the Auth key & Postman-Token varying slightly due to different requests). Everything in the "Network” section is exactly the same