twitch Calling Twitch APIs JavaScript


Example

The following will log the JSON response from the API to the console if the request was successful, otherwise it will log the error.

var xhr = new XMLHttpRequest();
  
xhr.open('GET', 'https://api.twitch.tv/kraken', true);
  
xhr.setRequestHeader('Client-ID', '...');
  
xhr.onload = function(data){
  console.log(data);
};
  
xhr.onerror = function(error){
  console.log(error.target.status);
};
  
xhr.send();