// Your API Key
const apiKey = "myapikey";
// The URL for the GET request
const url = "my_api_fetch_url";
// The GET request using fetch
fetch(url, {
method: "GET", // Specify the HTTP method
headers: {
"accept": "application/json", // Specify that we expect JSON in return
"content-type": "application/json", // Content type to application/json
"api_key": apiKey // API Key as required by the API
}
})
.then(response => {
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText}`);
}
return response.json(); // Parse the response JSON
})
.then(data => {
console.log("Success:", data); // Handle the successful response output
})
.catch(error => {
console.error("Error:", error); // Handle errors
});
That code come from Connected App call when click on a button
So that code not working, always get error 400
Fetch API cannot load due to access control checks
may be because of localhost :
https://127.0.0.1:5000/in my manifest i whitelist url etc
Note that in postman it works very well, i think is related with Host in the headers