Unable to get multiple channels in a single request

The documentation shows that you should be able to do the following and get multiple channels data return. Now I’m getting error ‘Bad Request’ with message ‘Unparsable request body’. This was working until Thursday between 2:53 and 2:58 pm, Central Time.

>>> headers = {'content-type': 'application/json', 'Client-ID': 'my_api_key'}
>>> res  = requests.get(url, headers=headers).json()
>>> res
{u'status': 400, u'message': u'Unparsable request body', u'error': u'Bad Request'}

You can still hit the ‘https://api.twitch.tv/kraken/streams/channel_name’ however that pulls only an individual channel and is very inefficent.

Did this endpoint change and is there a new way to get multiple channel data in a single request?

Thanks.


Edit:

Additional oddities:

Send the headers with my api key, along with api key in the url, get same error.

>>> url = 'https://api.twitch.tv/kraken/streams?channel=drlupo,kjhovey&client_id=my_api_key'
>>> res  = requests.get(url, headers=headers).json()
>>> res
{u'status': 400, u'message': u'Unparsable request body', u'error': u'Bad Request'}

Send the request with my api key in the url, omitting the headers, it works fine.

>>> url = 'https://api.twitch.tv/kraken/streams?channel=drlupo,kjhovey&client_id=my_api_key'
>>> res  = requests.get(url).json()
>>> {u'_total': 2, u'streams': ...

TL;DR - If I remove my API Client ID from the headers, and add it to the url, I can request multiple channels at the same time. If I put the Client ID in the header only, unable to get multiple channels data.

Try removing the Content-Type header if you’re not actually sending data via POST or PUT. I’ve ran into the same issue, apparently something changed about some API endpoints.

To specify what data you expect to receive you’d want the Accept header with application/vnd.twitchtv.v3+json (also specifying v3 of the API).

1 Like

Hey, that seems to have done the trick. Thank you!

Wow! My app stopped working one night last week and for the life of me I couldn’t work out why (kept getting 400 errors). This seems to have fixed it. How did you find the solution??
Thanks anyway :slight_smile:

Since Response Code 400 means “Bad Request” I looked at my request code and disabled the headers I’m sending one-by-one until I found the one causing it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.