I\'m trying to send an authenticated request with one click in postman.
So, I have request named \"Oauth\" and I\'m using Tests to store the token in a local variable.>
You can add a pre-request script to the collection which will execute prior to each Postman request. For example, I use the following to return an access token from Apigee
const echoPostRequest = {
url: client_credentials_url,
method: 'POST',
header:
'Authorization: Basic *Basic Authentication string*'
};
var getToken = true;
if (!pm.environment.get('token'))
{
console.log('Token missing')
}
else
{
console.log('Token all good');
}
if (getToken === true) {
pm.sendRequest(echoPostRequest, function (err, res) {
console.log(err ? err : res.json());
if (err === null) {
console.log('Saving the token');
console.log(res);
var responseJson = res.json();
console.log(responseJson.access_token);
pm.environment.set('token', responseJson.access_token)
}
});
}