I'm trying to use webUntis'(docs) API for a school project. For now I'm just trying to establish any kind of connection to the API.
var result;
const url = 'https://api.webuntis.dk/api/status';
var xhr = new XMLHttpRequest();
xhr.open('GET',url, true);
xhr.setRequestHeader('Access-Control-Allow-Origin','*');
xhr.setRequestHeader('Content-type','application/json');
xhr.setRequestHeader('Access-Control-Allow-Methods','GET');
xhr.setRequestHeader('X-API-KEY', '/*API KEY*/');
xhr.send();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
result = xhr.responseType;
console.log(result);
}
};
This code produces the following error message:
Cross-Origin request blocked: The same origin policy prohibits the reading of the external resource at https://api.webuntis.dk/api/status (Reason: CORS Header 'Access-Control-Allow-Origin' is missing).
How may this problem be solved? Perhaps my API key is wrong?
Disclaimer: The error message was translated from German.