Changing Twitch Status and Game with API v5

Hi, I’m creating a bot which I want to change the status of the stream. However, i cannot seem to see where I’m going wrong with the code below. I get the Oauth token here http://twitchapps.com/tokengen/ with the scopes channel_editor and channel_read however, i still get a ‘400 error bad request’

var title = ’ this is a title’;
$.ajax({
url: ‘https://api.twitch.tv/kraken/channel/lovenpk?channel[status]=’+ title+’&_method=put’,
type: ‘GET’,
contentType: ‘application/json’,
dataType: ‘jsonp’,
headers: {
‘Accept’ : ‘application/vnd.twitchtv.v5+json’,
‘client-ID’ :‘CLIENT_ID’,
‘Authorization’: ‘OAuth Oath-TOKEN’
},
success: function(data) {
console.log(data.status);
console.log(data)
}
});
});

Any help?

A few things:

  • With v5. you’re required to use a channel ID instead of a channel name in the URL. Right now, you’re passing in lovenpk instead of the channel ID. Docs here: https://dev.twitch.tv/docs/v5/guides/using-the-twitch-api/#translating-from-user-names-to-user-ids

  • You’re doing type: 'GET' but adding &_method=put as a URL parameter. I would remove the &_method=put and change to type: 'PUT'.

  • You need to URL-encode the value you’re sending for the status since it is a query string parameter.

1 Like

Thank you! I’ll give it a shot!

For those who are also having problem with this, below is the code for v5 of the Twitch API. It works!

$.getJSON(‘https://api.twitch.tv/kraken/users/CHANNEL_NAME?client_id=CLIENT_ID’).done(function(data){

		var title = 'cool story bruh';
		$.ajax({
            url: 'https://api.twitch.tv/kraken/channels/'+data._id+'?'+ encodeURI('channel[status]='+title),
            type: 'PUT',
            contentType: 'application/json',
           	headers: {
           		'Accept' : 'application/vnd.twitchtv.v5+json',
  				'client-ID' :'CLIENT-id',
                'Authorization':'OAuth OAuth_Token'
           	},
        	success: function(data) {
	         	console.log(data.status);
	         	console.log(data)
        	}
 		});
	});

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