I want to make a web page to allow the export of multiple dashboards. I want to use the HTTP API for this, but I always get this error message:
Access to XMLHttpRequest at ‘http://192.168.210.197:3000/api/search?type=dash-db’ from origin ‘http://192.168.210.197’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource
And the code is:
const startExport = () => {
let xhttp = new XMLHttpRequest();
let jwtoken = 'eyJrIjoieFlCNk5vdmV3WkdqZWl4eThWUXh1RmdZanNFOTNieVUiLCJuIjoiZXhwb3J0LmltcG9ydCIsImlkIjoxfQ==';
xhttp.onreadystatechange = () => {
console.log(this);
if (this.readyState == 4 && this.status == 200) {
document.getElementById('resultExport').innerHTML = this.responseText;
}
};
xhttp.open("GET", "http://192.168.210.197:3000/api/search?type=dash-db", true);
xhttp.setRequestHeader('Content-Type', 'application/json');
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader('Authorization', 'Bearer ' + jwtoken);
xhttp.send();
}
That is a first test to get all Dashboards from my Grafana instance.