Twitch API

Twitch provides a few different APIs with varying degrees of functionality. You can hit any of them directly from within an extension, however the MEDKit provides a convenience wrapper for some of the more common use cases.

Requesting Directly

You can use any js library or browser-native method to hit the Twitch API endpoints, passing your Extension Client ID as authorization.

window.fetch('https://api.twitch.tv/helix/users?login=twitch', {
  headers: {
    'Client-ID': '<extension client id>'
  }
})
.then((response) => response.json())
.then(({ data }) => {
  console.log(data[0]);
})
.catch(() => {
  console.error('Failed looking up user info');
});

The full list of Twitch API endpoints can be found here: https://dev.twitch.tv/docs/api/

MEDKit Wrapper

The MEDKit already knows your authorization info, so once you’ve created a client, you can call it directly.

const client = new Muxy.TwitchClient();
client.getTwitchUsersByID(['126955211'])
  .then((users) => {
    console.log(users[0]);
  });

Either request will return a data object like:

{
  "broadcaster_type": "partner",
  "description": "Twitch is the world's leading video platform and community for gamers with more than 100 million visitors per month. Our mission is to connect gamers around the world by allowing them to broadcast, watch, and chat from everywhere they play.",
  "display_name": "Twitch",
  "id": "12826",
  "login": "twitch",
  "offline_image_url": "",
  "profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/twitch-profile_image-8a8c5be2e3b64a9a-300x300.png",
  "type": "",
  "view_count": 214488775
}

Available Functions

TwitchClient.getTwitchUsers

https://dev.muxy.io/sdk/classes/sdk.twitchclient.html#gettwitchusers

Takes an array of usernames and returns an array of full user objects.

TwitchClient.getTwitchUsersByID

https://dev.muxy.io/sdk/classes/sdk.twitchclient.html#gettwitchusersbyid

Takes an array of Twitch user ids and returns an array of full user objects.