Empty Response Body After Adding Header in Script

I’m trying to run a script for an API where I retrieve User IDs based on their email addresses with a Get User call. This API requires a Bearer token and it works if I set it as the Authorization header in the UI, but I want to set it programatically since the token has a short lifespan.

This is my prerequest script for the Get User call (hard coding a test user right now until I get it working). It retrieves the token from a previous call in the runner iteration and adds it as the authorization header. This results in the below call construction:

(Redacted the tokens for security). This call does not have a request body. Everything here looks correct, and I know the API recieved a valid token because it returned a 200 OK response, otherwise it would have been a 401. I’m also able to use POST and PUT functions using this token without any issues. However, when using this GET call, the response body is empty.

If I set the Authoirzation header in the UI instead of the pre-request script, it works fine. The resposne body contains the user account information. This working call has the same request URL and headers as the one tha tisn’t working, just with a different token.

I can’t fathom why adding the authorization header in the pre-request script seems to be breaking my ability to read the response body. Any ideas?

I’m using Postman v9.30.0

Ok, I was able to fix it by changing my Get Token test script.

Incorrect:
pm.environment.set(“accessToken”, pm.response.json().access_token;);
pm.test(“Got Token”, function () {
pm.response.to.have.status(200);
});

Correct
const token = pm.response.json().access_token;
pm.environment.set(“accessToken”, token);
pm.test(“Got Token”, function () {
pm.response.to.have.status(200);
});

I don’t know why, but this one works.