Failing using the API because of CORS?

My tool used to call the API via Curl what is working without problems.
Now I want to change it and make it via JavaScript. The code is created and should work, but I get an error while executing the code. I made it as easy as possible and partly hardcoded to get it run once before make it more complex.

The code looks like:
async function run_make(params) {
const { ID } = params;

const url = [https://eu1.make.com/api/v2/scenarios/${ID}/run];

try {
let response = await fetch(url, {
method: ‘POST’,
headers: {
‘Authorization’: Token fead3e98-ce3d-42b2-b604-f2aa48e3xxxx,
‘Content-Type’: ‘application/json’ // Hinzugefügt, falls erforderlich
}
});

if (!response.ok) {
throw new Error(HTTP error! status: ${response.status});
}

let data = await response.json();
return data;
} catch (error) {
console.error(‘There was a problem with the fetch operation:’, error);
}
}

I tried different changes but always get the error undefined. Got the info of a friend, that it could happen because of CORS. Can you help me with this?

Where is this script being called from? Can you provide the link to the page?

Usually CORS header is set on the server hosting the website/page the script is calling, and in this case, Make blocks JS from running in web browsers to call their APIs.

Also, I don’t think the Make API should be called using JavaScript due to security issues.

These articles may help you further investigate the issue:

2 Likes

Thanks for the fast answer. I was calling via OpenAI function calling.
Its documented here:

Unfortunately, the functions can only be used with js. So it is not possible with make/ that way in my understanding correct?