REST api request from client side script

Hi! I want to make GET request to an api through client side script.
Code fragment:
frappe.call({
method: “GET”,
url: https://api.nbp.pl/api/exchangerates/rates/a/EUR/${formattedYesterdayDate}/,
Unfortunatley, I get Access to XMLHttpRequest at ‘https://api.nbp.pl/api/exchangerates/rates/a/EUR/2023-02-10/’ from origin ‘https://mysiteaddress’ 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.

I already have allow_cors | * in my site config, which I validated through bench show-config

I cannot manage to change cors policy on my server to overcome this, I would be thankful for any help!

fetch(`your-api-link`, {
        method: 'GET',
            headers: {
                'x-rapidapi-host': '',
                'x-rapidapi-key': '',
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
        })
        .then(r => r.json())
            .then(r => {
                //console.table(r);
            })
1 Like

Thanks, this method should work too, but the cors error persists. It must do with the configuration of the server. For now I solved the issue by manually inserting the required value each time it is needed in the document.