0

I'm having trouble connecting to the behance API. I registered my app, got my API key. And when I try it in my browser URL bar, everything works perfectly:

enter image description here

But whenever I try to fetch it via my app, it returns nothing (the body of the response is empty):

fetch(`https://api.behance.net/v2/projects?client_id=${API_KEY}`, {
  mode: 'no-cors'
})
  .then((res) => res.json())
  .then((data) => {
    console.log('DATA ', data)
  })
Uncaught (in promise) SyntaxError: Unexpected end of input
at line 63 index.js

Line 63 corresponds to .then((res) => res.json()) which makes sense since the response is empty.

I also have this warning (Which I'm guessing comes from the fact that the response body is empty too):

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://api.behance.net/v2/projects?per_page=25&client_id=[API_KEY] with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

Thanks in advance

Saraband
  • 1,540
  • 10
  • 18
  • Cleaning my browser cache made no difference, the request is still empty – Saraband Mar 16 '19 at 15:27
  • What is in the rest of `res`? Perhaps you are getting a non 200 status back and an error message that might help figure it out. Also, you might look at the headers in your successful browser request, to see if the browser is sending something that your fetch is not (no idea why that would happen, but worth a look). – Henry Mueller Mar 16 '19 at 18:09
  • Never use 'no-cors' mode. See the answer at https://stackoverflow.com/questions/43317967/handle-response-syntaxerror-unexpected-end-of-input-when-using-mode-no-cors/43319482#43319482. Anyway, the Behance API is intentionally not CORS-enabled. So you can’t call it directly from your frontend JavaScript code. It’s instead intended that you call it from your backend/server-side environment instead. – sideshowbarker Mar 17 '19 at 07:00

0 Answers0