MyBB Community Forums

Full Version: Fetching an API resource on mybb [CORS problem]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone ,
I'm trying to use an API on my mybb test forum and I get this error at every fetch on my console :
Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.

It seems like there is some CORS problem , I tried to fix it by adding into my apache2 htaccess file this code , but it doesn't work :

<IfModule mod_headers.c>
  
    Header set Access-Control-Allow-Origin "*"
  
</IfModule>



Please help me guys !
What’s the actual code you’re running? What is the API you’re calling?
So I'm running this code : fetch('http://v2.api.iphub.info/ip/${ipaddress}', {
"X-Key": 'APIKEY'

})
.then(response => response.json())
.then(data => console.log(data));

( the code I m using is bigger but I used this as an example .. maybe the problem is coming because I m not using async await ?? but I don t think so ..
As far as I’m aware you won’t be able to do it. CORS needs to be set up on the remote server, not yours. You’ll need to do this API call server side.
(2022-03-06, 08:32 PM)Matt Wrote: [ -> ]As far as I’m aware you won’t be able to do it. CORS needs to be set up on the remote server, not yours. You’ll need to do this API call server side.
oh so I should do it in php ??