How to hit the Twitch API

The Twitch Helix API at https://api.twitch.tv/helix needs two things on every call: your app's Client-Id header and an OAuth token.

Authentication

Register an app in the Twitch developer console for a client id and secret, then get an app access token with the first call below. In the examples they're {{TWITCH_CLIENT_ID}}, {{TWITCH_CLIENT_SECRET}}, and {{TWITCH_TOKEN}}.

Full reference: https://dev.twitch.tv/docs/api/reference/

Get an app access token

curl -X POST https://id.twitch.tv/oauth2/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "client_id={{TWITCH_CLIENT_ID}}&client_secret={{TWITCH_CLIENT_SECRET}}&grant_type=client_credentials"
Run in PostTaco

Top live streams

curl "https://api.twitch.tv/helix/streams?first=5" \
  -H "Client-Id: {{TWITCH_CLIENT_ID}}" \
  -H "Authorization: Bearer {{TWITCH_TOKEN}}"
Run in PostTaco

Look up a user

curl "https://api.twitch.tv/helix/users?login=twitchdev" \
  -H "Client-Id: {{TWITCH_CLIENT_ID}}" \
  -H "Authorization: Bearer {{TWITCH_TOKEN}}"
Run in PostTaco