# Loading stream information json into Glitch Twitchbot

**URL:** <https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048>\
**Category:** API\
**Created:** [June 1, 2020, 6:02am UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048 "2020-06-01T06:02:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [June 1, 2020, 6:02am UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/1 "2020-06-01T06:02:43Z")

</div>

Recently started working on the Twitch Chatbot and have the bot doing very basic commands but as soon as I attempt to request stream information I get a bit lost. When I do an online Curl Request I can get all the json data no problem. However when I try to fetch in the Glitch bot.js I just get

> error: ‘Bad Request’,  
> status: 400,  
> message: ‘No client id specified’

Any ideas?

I also tried to migrate to the new helix API but I cant seem to figure out the new https.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 1, 2020, 10:41am UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/2 "2020-06-01T10:41:44Z")

</div>

For helix you need to include a oAuth header and a ClientID.

That error suggests you omitted the clientID and probably that oAuth token.

So you need to show your code so we can help

and read

> **[Authentication](https://dev.twitch.tv/docs/authentication/)**
>
> Authentication

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [June 1, 2020, 5:08pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/3 "2020-06-01T17:08:47Z")

</div>

That error was from the kraken api because I’ve been a bit unsure about the format of the helix.  
Here is the fetch I was using on the kraken api.

> fetch(‘[https://api.twitch.tv/kraken/streams/\_id](https://api.twitch.tv/kraken/streams/_id)’)

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 1, 2020, 5:10pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/4 "2020-06-01T17:10:22Z")

</div>

if thats\_all\_ you specified, then you have not incldued any headers with your request

```
fetch(
    ‘https://api.twitch.tv/kraken/streams/_id’,
    headers: {
        'Client-ID': YOURCLIENT,
        'Accept': 'application/vnd.twitchtv.v5+json'
    }
)
```

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [June 20, 2020, 6:48pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/5 "2020-06-20T18:48:43Z")

</div>

Thankyou Barry this helped alot and got it all working for me but I’m starting to realize I should probably make the switch to the new Helix api. Any idea how to translate the fetch over to helix? I assume it will return a similar json.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 20, 2020, 6:52pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/6 "2020-06-20T18:52:31Z")

</div>

```auto
fetch(
    ‘https://api.twitch.tv/helix/streams?user_id=’ + id,
    headers: {
        'Client-ID': YOURCLIENT,
        'Authorization': 'Bearer ' + YOURTOKEN
    }
)

```

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [June 21, 2020, 12:11am UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/7 "2020-06-21T00:11:01Z")

</div>

That’s currently only returning

> [object Object]

Assuming the ‘YOURTOKEN’ is my OAUTH\_TOKEN I’m not sure what I did wrong.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 21, 2020, 11:16am UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/8 "2020-06-21T11:16:38Z")

</div>

The response needs to be JSON parsed. Before it can be used. Depending on the rest of your code

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [July 8, 2020, 10:00pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/9 "2020-07-08T22:00:02Z")

</div>

So it returns data in a different format than kraken api does?

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [July 8, 2020, 10:21pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/10 "2020-07-08T22:21:58Z")

</div>

Here’s what I’m working with.

```
function fetchChatter()
{
fetch('https://api.twitch.tv/helix/streams?user_id=' + chatterUID, {
headers: {
    'Client-ID': process.env.Client_ID,
    'Authorization': 'Bearer ' + process.env.OAUTH_TOKEN
         }
})
.then(function(resp)
   {
      console.log(resp.json());
        //return resp.json();
  })
```

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 8, 2020, 10:48pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/11 "2020-07-08T22:48:48Z")

</div>

> [@RyanBuech](#):
>
> So it returns data in a different format than kraken api does?

Yes, it’s still JSON just formatted different

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [July 9, 2020, 2:29am UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/12 "2020-07-09T02:29:21Z")

</div>

So any idea why it’s just returning

```
 {object Object}
```

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 9, 2020, 11:25am UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/13 "2020-07-09T11:25:56Z")

</div>

your code example seems incomplete above.

If you are getting an object that suggests that you didn’t json decode

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [July 9, 2020, 4:30pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/14 "2020-07-09T16:30:12Z")

</div>

I’m not completely sure what you mean by json decode sorry.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 9, 2020, 6:03pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/15 "2020-07-09T18:03:12Z")

</div>

> [@RyanBuech](#):
>
> ```auto
> function fetchChatter()
> {
> fetch('https://api.twitch.tv/helix/streams?user_id=' + chatterUID, {
> headers: {
> 'Client-ID': process.env.Client_ID,
> 'Authorization': 'Bearer ' + process.env.OAUTH_TOKEN
> }
> })
> .then(function(resp)
> {
> console.log(resp.json());
> //return resp.json();
> })
> 
> ```

Your call to `resp.json()` is one method of calling a json decode. It’s a javascript/API basic since the data is returned as a string and has to be parsed for use, it’s a bit of a fundamental

You probably need to do

```auto
.then(function(resp)
   {
        return resp.json();
  })
.then(function(resp) 
  {
      console.log(resp);
  })

```

To solve the issue you are having.

I’m not sure what the issue is as all you are doing is logging the output not parsing/using it at all.

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [July 9, 2020, 6:30pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/16 "2020-07-09T18:30:19Z")

</div>

Here is the current code if you have a chance to take a look.  
[rudeoffBOT](https://glitch.com/edit/#!/rudeoffbot)  
The issue I’m currently having is transitioning from kraken to helix. The helix fetch is just returning an empty object.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 9, 2020, 6:32pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/17 "2020-07-09T18:32:16Z")

</div>

> [@RyanBuech](#):
>
> The issue I’m currently having is transitioning from kraken to helix. The helix fetch is just returning an empty object.

That would suggest the stream you are looking up is not live, hence the empty object

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [July 9, 2020, 7:17pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/18 "2020-07-09T19:17:42Z")

</div>

> [@RyanBuech](#):
>
> `https://api.twitch.tv/helix/streams?user_id=`

I thought this could be used to check a user’s stats inreguards to the stream such as when they followed.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 9, 2020, 7:19pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/19 "2020-07-09T19:19:24Z")

</div>

That is the stream endpoint it returns information about that user\_id’s stream if the stream is live.

Otherwise it doesn’t return anything as there is no live stream to return the details of

---

<div class="post-metadata">

**Author:** ![RyanBuech](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ryanbuech/32/8891_2.png) [@RyanBuech](https://discuss.dev.twitch.com/u/RyanBuech)\
**Post date:** [July 9, 2020, 7:34pm UTC](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048/20 "2020-07-09T19:34:30Z")

</div>

Just went live to test and I still received the same result.  
Also tested with  
fetch(‘[https://api.twitch.tv/helix/users/follows?to\_id=](https://api.twitch.tv/helix/users/follows?to_id=)’ + chatterUID, {

[Next page](https://discuss.dev.twitch.com/t/loading-stream-information-json-into-glitch-twitchbot/26048.md?page=2)
