Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Api

Make requests to Twitch API.

Initializing

const token = 'cfabdegwdoklmawdzdo98xt2fo512y'
const clientId = 'uo6dggojyb8d6soh92zknwmi5ej1q2'
const { api } = new TwitchJs({ token, clientId })

Making requests

By default, the API client makes requests to the Helix API, and exposes Api.get, Api.post and Api.put methods. Query and body parameters are provided via options.search and options.body properties, respectively.

Examples

Get bits leaderboard

api
  .get('bits/leaderboard', { search: { user_id: '44322889' } })
  .then(response => {
    // Do stuff with response ...
  })

Get the latest Overwatch live streams

api
  .get('streams', { search: { game_id: '1234' } })
  .then(response => {
    // Do stuff with response ...
  })

Start a channel commercial

api
  .post('/channels/commercial', {
    body: { broadcaster_id: '44322889', length: 30 },
  })
  .then(response => {
    // Do stuff with response ...
  })

Hierarchy

  • Api

Index

Constructors

constructor

  • Parameters

    Returns Api

Properties

Private _log

_log: Logger

Private _options

_options: ApiOptions

Private _readyState

_readyState: ApiReadyStates = ApiReadyStates.READY

Private _status

Accessors

readyState

status

Methods

Private _getAuthenticationHeaders

  • _getAuthenticationHeaders(): RequestInit["headers"]
  • Returns RequestInit["headers"]

Private _handleAuthenticationFailure

  • _handleAuthenticationFailure(originError: Error): Promise<undefined | string>
  • Parameters

    • originError: Error

    Returns Promise<undefined | string>

Private _handleFetch

  • _handleFetch<T>(maybeUrl?: string, options?: ApiFetchOptions): Promise<T>
  • Type parameters

    • T = any

    Parameters

    • Default value maybeUrl: string = ""
    • Default value options: ApiFetchOptions = {}

    Returns Promise<T>

get

  • GET endpoint.

    example
    Get user follows (Helix) ``` api.get('users/follows', { search: { to_id: '23161357' } }) .then(response => { // Do stuff with response ... }) ```

    Type parameters

    • T = any

    Parameters

    Returns Promise<T>

hasScope

  • hasScope(scope: string): Promise<boolean>

initialize

  • initialize(newOptions?: Partial<ApiOptions>): Promise<void>

post

  • POST endpoint.

    Type parameters

    • T = any

    Parameters

    Returns Promise<T>

put

  • PUT endpoint.

    Type parameters

    • T = any

    Parameters

    Returns Promise<T>

updateOptions

  • updateOptions(options: Partial<ApiOptions>): void
  • Update client options.

    Parameters

    Returns void

Generated using TypeDoc