I am currently working on a script to automate the generation of my authentication bearer token for collections. This way, I won't have to manually pass the token each time and can inherit authentication from the parent. However, I seem to be encountering an issue with the script as it is not successfully generating the token and is throwing an error.
An error occurred while evaluating the Pre-request Script: Error: No data, empty input at 1:1 ^
Below is the script in question:
var expiresOn = pm.variables.get('ExpiresOn');
if (!expiresOn || new Date(expiresOn) <= new Date()) {
var clientId = '565v7677676vfdrd';
var apiToken = '6565fdvdrdfd';
var request = {
url: 'http://.../auth/token',
method: 'POST',
header: 'Content-Type: application/json',
body: {
mode: 'raw',
raw: clientId + apiToken
}
};
}
};
pm.sendRequest(request, function (err, res) {
if (res !== null) {
var json = res.json();
pm.environment.set('Access_Token', json.access_token)
var expiresOn = new Date(0);
expiresOn.setUTCSeconds(json.expires_on);
pm.environment.set('ExpiresOn', expiresOn);
}
});
}