I am trying to make a fetch call to a web server via apis.
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch(
"https://api-mainnet.magiceden.dev/v2/collections?offset=0&limit=3",
requestOptions
)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
This seems to throw this error enter image description here
Access to fetch at 'https://api-mainnet.magiceden.dev/v2/collections?offset=0&limit=3' from origin 'null' has been blocked by CORS policy: 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.
But the same url if I try to access in the browser . Displays the data. enter image description here Any help on how I can get the fetch api call to work would be much appreciated.
What Are your "requestOptions"? I've tried this, and it's working fine.
fetch("https://api-mainnet.magiceden.dev/v2/collections?offset=0&limit=3" )
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));