Certain get request not working in workers. but works in browser

hi, anyone know why i cant do fetch on this endpoint? keep getting 400 bad request. it works fine in browser. const streamIngestUrlRes = await fetch('https://ingest.twitch.tv/ingests')
4 Replies
James
James8mo ago
It’s possible they’re blocking requests from workers, or without a user agent, or ones that don’t look like real browsers. You could try adding headers to make it look like a real browser first.
honzabit
honzabit8mo ago
curl -XGET returns the json data and it sends these request headers:
> Host: ingest.twitch.tv
> User-Agent: curl/8.4.0
> Accept: */*
> Host: ingest.twitch.tv
> User-Agent: curl/8.4.0
> Accept: */*
Gagan Suie
Gagan SuieOP8mo ago
i get this error when i do await streamIngestUrlRes.json()
X [ERROR] Uncaught (in response) SyntaxError: Unexpected end of JSON input
X [ERROR] Uncaught (in response) SyntaxError: Unexpected end of JSON input
as a work-around, im just making the call in the frontend and sending the data to the backend.
honzabit
honzabit8mo ago
Well, at some point the request might return a TLS error, even from the browser (try hard-refreshing multiple times). So maybe it's not your problem. You can put a retry on fetch in case of such error.
Want results from more Discord servers?
Add your server