I've a problem with the OAuth for the authentication to the API of Meteomatics.
The think I'm trying to do is to get the data from the API of Meteomatics (I've a Basic account). The API respond to me that I've to authenticate but when I set the header for get the token it gave me an error.
The documentation says that I've to put the script below:
var username = '<my_username>';
var password = '<my_password>';
let headers = new Headers();
headers.set('Authorization', 'Basic' + btoa(username + ":" + password));
fetch('https://login.meteomatics.com/api/v1/token', {
//mode: 'no-cors',
method: 'GET',
headers: headers
}).then(function (resp) {
return resp.json();
}).then(function (data) {
var token = data.access_token;
console.log('token', token);
}).catch(function (err) {
console.log('something went wrong', err);
});
The console give me this error:
image of error.
I've read something about CORS, but I don't understand what is the problem. Am I missing something ?
Thanks in advance for those who reply.