How to check if specific streamer is online in node.js

Hey guys! I’m not good at programming, and just doing a small chatbot, and for him I need to have info if the streamer is Live…

Thanks to this video: https://www.youtube.com/watch?v=-0ASwlMcWik and this querry: https://dev.twitch.tv/docs/api/reference/#get-streams

… I’ve managed to write a code that gets top 100 streamers from the server… I’m trying to ask it only for single streamer with parameters like “user_login” or “user_id”, but that is not working, and it keep sending me just a top 100 streamers list…

Can you help me?.. I’ve never dealt with web requests logic… Here is my code:

request = require(`request`);

CLIENT_ID = ID;
CLIENT_SECRET = SECRET;
GET_TOKEN = " https://id.twitch.tv/oauth2/token";
GET_STREAM = "https://api.twitch.tv/helix/streams"

getToken = (url, callback) => {
	const options = {
		url: GET_TOKEN,
		json: true,
		body: {
			client_id: CLIENT_ID,
			client_secret: CLIENT_SECRET,
			grant_type: "client_credentials"
		}
	};
	
	request.post(options, (err, res, body) => {
		if(err) {
			return console.log(err);
		}
		console.log(`Status: ${res.statusCode}`);
		console.log(body);
		
		callback(res);
	});
};

var AT = ``;
getToken(GET_TOKEN,(res) => {
	console.log(res.body);
	AT = res.body.access_token;
	return AT;
});


const getStream = (url, accessT, callback) =>{
	const streamOptions = {
		url: GET_STREAM,
		method: "GET",
		headers: {
			'broadcaster_id': `39640696540`,
			'Client-ID': CLIENT_ID,
			'Authorization': `Bearer ${accessT}`,
			'user_login': `imTheSupremeOne`
			//'user_id': `39640696540`
		}
	}
	
	request.get(streamOptions, (err, res, body) => {
		if(err) {
			return console.log(err);
		}
		console.log(`Status: ${res.statusCode}`);
		console.log(JSON.parse(body));
	});
};

setTimeout(() => {
	//console.log(AT);
	getStream(GET_STREAM, AT, (response) =>{})
}, 2000)

Admin: Fixed code formatting

broadcaster ID/userID/Login is a query string parameter, not a header

You should be calling as the URL

http://api.twitch.tv/helix/streams?user_login=imTheSupremeOne

or doing something like

	const streamOptions = {
		url: GET_STREAM,
		method: "GET",
		headers: {
			'Client-ID': CLIENT_ID,
    		'Authorization': `Bearer ${accessT}`
        },
        qs: {
			'user_login': `imTheSupremeOne`
		}
	}

Also worth noting request is deprecated/will not be updated.

See