I am trying to write a Postman pre-request script that will set my env variable for the token. I've taken one of my other working scripts and modified it for this type of response but am having issues.
I have a web service that returns the Auth Token back in the request as follows
I have a script that should parse the new token but it throws an error
pm.sendRequest({
url: pm.environment.get("token_endpoint")+ '?username=' + pm.environment.get("username") + '&password='+ pm.environment.get("password"),
method: 'GET',
},
function (err, res) {
if (err) {
throw err;
}
if (res.code !== 200) {
throw new Error('Could not log in.');
}
console.log(`New token is: ${res.json()}`);
});
my error trying to log the token is
JSONError: Unexpected token 'e' at 1:1 eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiU2VydmljZURpcmVjdG9yQVBJIiwibm
I've tried a few different ways to pull that in but nothing logs the token as you would expect. What am I doing wrong here?