How to create a proper ajax-request using API?

Hello.

I’m trying to build an app similar to this https://codepen.io/freeCodeCamp/full/Myvqmo (you can’t see online and offline channels, because API rules changed and every app similar to this don’t work).

So, I use an ajax-request and add a client-id
$.ajax({
url: “https://api.twitch.tv/helix/search/channels/ESL_SC2”,
type: “GET”,
async: false,
headers: {
‘Client-ID’: ‘Client-ID’
}

But despite of that, I get a 404 mistake. According to these rules, you need an “Authorization” in the “headers”, but I can’t understand where I should get this authorization key.

So could you please help me to create a proper ajax-request?

Your URL is wrong

You need to call Get Streams https://api.twitch.tv/helix/streams with the user_login param instead, for online/offline checking.

https://api.twitch.tv/helix/streams?user_login=esl_sc2

The search API is for searching, and the correct URL for that would be

https://api.twitch.tv/helix/search/categories?query=esl_sc2

As for tokens, since this is an ajax call an implicit token is most appropriate

You will need to prompt the user to login with Twitch to get a token that you can use in the front end.

This example, will call the users API but you can substitute as needed: Twitch Implicit Auth Example

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