0

I want to call API with axios, and my problem is that when I paste the endpoint in my browser it return the JSON response, but when I call it with axios i got an error any idea why ?

axios
    .get("https://remotive.io/api/remote-jobs")
    .then((res) => console.log(res));

Error :

Access to XMLHttpRequest at 'https://remotive.io/api/remote-jobs' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Joey
  • 121
  • 2
  • 12
  • 2
    `remotive.io` doesn't allow CORS access - here's some [documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) and a [video](https://www.youtube.com/watch?v=PNtFSVU-YTI) – Bravo Sep 10 '21 at 16:09
  • Got it, but can you explain to me how could this API be called inside, I mean is this something I can fix ? And if they won't allow it, why they made the API at first ? – Joey Sep 10 '21 at 16:11
  • generally it's not uncommon for OPTIONS responses to include CORES header only for valid referrers, so while CORS could allow some origins, it does not list http://localhost:3001. You can't "fix" it, it's a configuration choine on `remotive.io` to stop you from calling their APIs on other websites. – erik258 Sep 10 '21 at 16:12
  • 1
    *"is this something I can fix"* - if it's not yours, then it's not broken, it's functioning as intended. It possibly was never intended to be used direct from a browser - likely it was made to be used from your server to their server - *"why they made the API at first"* = not sure what that API is for, so I can't answer that – Bravo Sep 11 '21 at 00:40

0 Answers0