Snekfetch (Node.js) Twitch API calls - Getting if a Streamer is live

I’m new to the Twitch API and trying to make a discord bot which will make a notification when a streamer is live.

However instead of returning the json object of the specified streamer, it seems to grab the entire front page of Twitch, and it returns 65966 results instead of just 1.

const streamer = 'insertstreamerhere';

const api = `https://api.twitch.tv/kraken/streams?&user_login="${streamer}"`;
const announcements = bot.channels.find(`name`, "announcements");

snekfetch.get(api).set('Client-ID', "XXXXXXXXXXXXX").then(r => {
    if (r.body.stream === null) {
        setInterval(() => {
            snekfetch.get(api).then(console.log(r.body))
        }, 30000);
    } else {
        //Do other stuff console.log is temporary
        console.log(r.body);

I’m not quite sure what I’m doing wrong, or if I’m misunderstanding the documentation.

Any clarification / insight is appreciated.

Thanks in advance

The reason you’re getting the first page of results from the entire stream list is because you’re effectively sending a request to https://api.twitch.tv/kraken/streams as your URL has issues.

There’s 3 problems here, first off you’re attempting to use the querystring param user_login which is for the Helix streams endpoint, but you’re requesting the old Kraken endpoint. The endpoint should be https://api.twitch.tv/helix/streams.

Secondly, your querystring is malformed. A question mark ? is used to indicate the start of the querystring, and the ampersand & is used to separate each key/value pair. So you need to remove that ampersand.

Finally, the double quotes around ${streamer} shouldn’t be used as they are not part of the streamers username.

The correct URL would be https://api.twitch.tv/helix/streams?user_login=${streamer}

Thanks a lot, that’s solved my problem. The ?& was a typo but thanks for the explanation and clarification.

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