Videos enpoint returns empty data array for game_id

Request for videos for ex. Counter-Strike: Global Offensive https://api.twitch.tv/helix/videos?game_id=32399 returns an empty array in response:

{
    "data": [],
    "pagination": {}
}

but in web version there are tons of videos
https://www.twitch.tv/directory/game/Counter-Strike%3A%20Global%20Offensive/videos/all
Looks like some kind of bug.

Are you making the request from a web browser context rather than a server context?

Seems like a similar issue to what is described here: Games endpoint empty data array when specifying a game_id · Issue #651 · twitchdev/issues · GitHub

does it metter? actually, i tried both. looks like there are some bug or just not updated api docs

I get videos here using a “server context”, in this case the TwitchCLI

twitch api get ‘games?name=Counter-Strike: Global Offensive’

To confirm the game ID

twitch api get ‘videos?game_id=32399’

To call the videos endpoint

Yes, as it works fine “from a server” to me.

yeah. twitch cli and curl works fine. but node js’s fetch does not. strange behaviour. thanks for help. i will search solution

Hmmm yeah doing a test here I don’t get videos…

Ok it works with node-fetch

But it doesn’t work with fetch that is in NodeJS “core”. Not sure what the difference is though

So

using “core fetch”

let r = await fetch(
    'https://api.twitch.tv/helix/videos?game_id=32399',
    {
        method: 'GET',
        headers: {
            'Client-ID': `${client_id}`,
            'Authorization': `Bearer ${token}`,
            'Accept': 'application/json'
        }
    }
);
let p = await r.json();

console.log(p);

Result:

But using node-fetch does work

import fetch from 'node-fetch';

let r = await fetch(
    'https://api.twitch.tv/helix/videos?game_id=32399',
    {
        method: 'GET',
        headers: {
            'Client-ID': `${client_id}`,
            'Authorization': `Bearer ${token}`,
            'Accept': 'application/json'
        }
    }
);
let p = await r.json();

console.log(p);

Fix: set a “bad” accept-language header

let url = 'https://api.twitch.tv/helix/videos?game_id=32399';

let r = await fetch(
    url,
    {
        method: 'GET',
        headers: {
            'Client-ID': `${client_id}`,
            'Authorization': `Bearer ${token}`,
            'Accept': 'application/json',
            'accept-language': 'YOUWHAT'
        }
    }
);
let p = await r.json();

console.log(p);

Why this works? I have no idea.

1 Like

yeah. that’s works. thank’s a lot. may be additional hidden filter applies to request based on this header

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