Axios setting gamename

Hi,
I have been attempting to write a node.js twitch bot. I have got most of the commands i need done but am struggling with setting the game name, I have figured out how to set with the following:

     if(command === 'title') {
                if(isModUp) {
                        streamtitle = args;
                        streamtitle = streamtitle.toString();
                        streamtitle = streamtitle.replaceAll(',', ' ');
                        headers = {
                                'Authorization':'Bearer OAUTH HERE',
                                'Client-Id':'CLIENT ID HERE',
                                'Content-Type':'application/json'
                        };
                        data = {
                            'title':`${streamtitle}`
                        };
                        axios.patch('https://api.twitch.tv/helix/channels?broadcaster_id=123393473', data, {'headers':headers});
                }else{ 
            };
        };

Basically im am struggling to find what to put inside the data variable to set game.
is it game, gamename etc

e.g. when i try the following:

        if(command === 'game') {
                if(isModUp) {
                        gametitle= args;
                        gametitle= gametitle.toString();
                        gametitle= gametitle.replaceAll(',', ' ');
                        headers = {
                                'Authorization':'Bearer 2mipvcn5skx2xf8n4rzv9t0zpf8vx0',
                                'Client-Id':'pv288tr1yt623898ifv8vmqzl62pzb',
                                'Content-Type':'application/json'
                        };
                        data = {
                            'game':`${gametitle}`
                        };
                        axios.patch('https://api.twitch.tv/helix/channels?broadcaster_id=123393473', data, {'headers':headers});
                }else{ 
            };
        };

i get “AxiosError: Request failed with status code 401”
Thank you

The HTTP code is half the information.

The API will also respond with a JSON payload that will describe the problem

A common ussue is that you have the wrong token type (app access/client credentials) or you generate a user token for 123393473 that doesn’t include the scope channel:manage:broadcast see Reference | Twitch Developers

Thank you i still have the issue with setting game but setting title now works, but noticed i put one letter wrong in my token making it invalid.
setting is confirmed working.

                        data = {
                            'title':`${streamtitle}`
                        };
                        axios.patch('https://api.twitch.tv/helix/channels?broadcaster_id=123393473', data, {'headers':headers});

I still have issue setting game.
I think maybe the name im passing is incorrect as im getting error code 400.

                     data = {
                            'game':`${gametitle}`
                        };
                        axios.patch('https://api.twitch.tv/helix/channels?broadcaster_id=123393473', data, {'headers':headers});

What the body message of the response.

The HTTP code is half the information

Only accept game_id not game name

So you have to convert a game_name to a game_id using the games API

Thank you, i got it working.
it wasn’t using the .then & .catch and as such the promise wasn’t being handled correctly

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