I am trying to establish a pre-request script in postman but I get error "Full authentication is required" because when I send the authorization in the header it is not being taken into account (As I see in the console). This is strange because when I use that same header in a separate request it works fine and generates the desired token.
This is my pre-request code:
var username = pm.environment.get("username");
var password = pm.environment.get("password");
const echoPostRequest = {
url: myURL(I deleted due the security reasons),
method: 'POST',
timeout: 0,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic xxxxxxxxxxxxx"
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: "grant_type", value: "password", disabled: false},
{key: "username", value: username, disabled: false},
{key: "password", value: password, disabled: false}
]
}
}
pm.sendRequest(echoPostRequest, function (err, response) {
console.log(response.json())
//console.log('Saving the token ')
//var responseJson = response.json();
// pm.environment.set('access_token', responseJson.access_token)
});
thank you very much for helping me with this!