Hi, I’ve got quite an interesting case
pm.sendRequest({
url: 'AUTHURL',
method: 'POST',
header: {
'Content-type': 'application/json',
'Accept': '*/*'
},
body: {
mode: 'raw',
raw: JSON.stringify({
login: env_variables.client_id,
password:env_variables.client_secret
})
}
}, (err, res) => {
if (err) {
console.error('Error while generating a bearer token:', err);
} else {
console.log(res.text()); // i can see data here
var {access_token} = res.text(); //
console.log(access_token); // outputs null
env_variables.auth_token = res.text(); //OK. I can see token in my environment.
pm.environment.set('auth_token', res.text()); //OK. I can see token in my collection
pm.environment.set("OAuth_Timestamp", new Date());
// Set the ExpiresInTime variable to the time given in the response if it exists
//pm.environment.set("ExpiresInTime", expiresInTime);
}
});
The response is text/plain. See inline comments. It is interesting that an assignment of the text variable results in that variable being null , as if assignment hasn’t been performed. When assigning the response of the request directly to the environment variable it works.
P.S this is a simple variable, so serialization/deserialization shouldn’t matter here, but i did try to play around with JSON conversions just for fun. It didn’t change much the result.
Thanks for your attention
EDIT: i modified my post with the latest info.