First off, I just want to say that I know that this question maybe should have been posted in a different forum but i'm trying here first.
I have already made a Powershell script that gathers information from the API, calculates some stuff and then previews it in a nicely formatted html table
Just for fun, I am now trying to make a html with javascript for API call. Im doing things in baby steps here, so I've been able to to collect the token. But when I'm trying to use the token for API calls. I'm just getting this error:
Access to fetch at 'https://localhost:4443/v4/backupreposit ... 90f54e7393' from origin 'null' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
To my understanding this can happen because of a couple of diferent reasons, but in my in my situation I think it is happening because the call is coming from a different Port than 4443 (I'm creating the html on the veeam server).
I can see that the first response from Veeam API where I request the token contains "access-control-allow-origin": "*" in the header, but all other responses does not.
Is there something I can add to my javascript to solve this or does anyone know a different way to solve it? I've been trying to read about CORS and to my understanding it's the response from the API that must contain the policy. Is this something that must be solved in the backend?
Here is my simple javascript that I just made with Postman:
Code: Select all
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer Removed token brecause it's length...");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://localhost:4443/v4/backuprepositories?proxyid=ef004d36-9ced-4779-92f2-e095f44e7392", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));