Contents

Webhooks Reference 

Endpoint Description
Subscribe To/Unsubscribe From Events Subscribe to or unsubscribe from events for a specified topic.

Subscribe To/Unsubscribe From Events

Subscribe to or unsubscribe from events for a specified topic.

Webhook response payloads mimic their respective New Twitch API endpoint responses (with minor omissions for unnecessary fields). That is, a call to a webhook returns in its payload the same data as a call to the corresponding endpoint in the new Twitch API.

Also see the Get Webhooks Subscriptions endpoint.

Note: Subscription requests affect rate limits in the new Twitch API.

Authentication

None

URL

POST https://api.twitch.tv/helix/webhooks/hub

JSON Body Parameters

NameTypeDescriptionRequired?
hub.callbackstringURL where notifications will be delivered.Yes
hub.modestringType of request. Valid values: subscribe, unsubscribe.Yes
hub.topicstringURL for the topic to subscribe to or unsubscribe from. topic maps to a new Twitch API endpoint. We support these topics:
  • User Follows — Notifies when a follows event occurs.
  • Stream Changed — Notifies when a stream changes; e.g., stream goes online or offline, the stream title changes, or the game changes.
  • User Changed — Notifies when a user changes information about his/her profile.
  • Game Analytics — Notifies when a new analytics report (CSV file) is available for a game.
  • Extension Analytics — Notifies when a new analytics report (CSV file) is available for an extension.
Yes
hub.lease_secondsintNumber of seconds until the subscription expires. Default: 0. Maximum: 864000.

The default (0) allows you to test the subscription-creation workflow without creating any subscriptions (since they expire immediately). After testing, to actually create subscriptions, you must specify a larger value.
No
hub.secretstringSecret used to sign notification payloads. The X-Hub-Signature header is generated by sha256(secret, notification_bytes). We strongly encourage you to use this, so your application can verify that notifications are genuine.No

Topic: User Follows

Notifies when a follows event occurs. The response mimics the Get Users Follows endpoint.

hub.topic URL

https://api.twitch.tv/helix/users/follows

Required Query String Parameters

The first parameter must be specified, along with from_id and/or to_id.

Name Type Description
first int Must be 1.
from_id int Specifies the user who starts following someone.
to_id int Specifies the user who has a new follower.

Example hub.topic URLs

Example Notification Payload

{
   "data":
      [{
         "from_id":"1336",
         "from_name":"ebi",
         "to_id":"1337",
         "to_name":"oliver0823nagy",
         "followed_at": "2017-08-22T22:55:24Z"
      }]
}

Topic: Stream Changed

Notifies when a stream changes; e.g., stream goes online or offline, the stream title changes, or the game changes. The response mimics the Get Streams endpoint.

hub.topic URL

https://api.twitch.tv/helix/streams

Required Query String Parameter

Name Type Description
user_id int Specifies the user whose stream is monitored.

Example hub.topic URL

User 5678’s stream changes: https://api.twitch.tv/helix/streams?user_id=5678

Example Notification Payload for Stream Offline Event

{
   "data": []
}

Example Notification Payload for Other Stream Change Events

{
   "data":
      [{
         "id":"0123456789",
         "user_id":"5678",
         "user_name":"wjdtkdqhs",
         "game_id":"21779",
         "community_ids":[],
         "type":"live",
         "title":"Best Stream Ever",
         "viewer_count":417,
         "started_at":"2017-12-01T10:09:45Z",
         "language":"en",
         "thumbnail_url":"https://link/to/thumbnail.jpg"
      }]
}

Topic: User Changed

Notifies when a user changes information about his/her profile. The response mimics the Get Users endpoint. This webhook requires the user:read:email OAuth scope, to get notifications of email changes.

hub.topic URL

https://api.twitch.tv/helix/users

Required Query String Parameter

NameTypeDescription
idintSpecifies the user whose data is monitored.

Example hub.topic URL

User 1234’s profile data changes: https://api.twitch.tv/helix/users?id=1234

Example Notification Payload

{
   "data":
      [{
         "id": "1234",
         "login": "1234login",
         "display_name": "hiiam1234",
         "type": "staff",
         "broadcaster_type": "",
         "description": "1234 is me",
         "profile_image_url": "https://link/to/pic/1234.jpg",
         "offline_image_url": "https://link/to/offline_pic/1234_off.jpg",
         "view_count": 3455
      }]
}

Topic: Game Analytics

Notifies when a new analytics report (CSV file) is available for a game. The response mimics the Get Game Analytics endpoint. This webhook requires the analytics:read:games OAuth scope.

hub.topic URL

https://api.twitch.tv/helix/analytics/games

Required Query String Parameter

NameTypeDescription
game_idstringSpecifies the game whose report data is provided.

Example hub.topic URL

Get notified of analytics data for game 1234: https://api.twitch.tv/helix/analytics?game_id=1234

Example Notification Payload

{
   "data":
      [{
         "game_id": "1234",
         "URL": "https://twitch-report-signed-url-1234.csv",
         "type": "overview_v1",
         "date_range": {
            "started_at": "2018-01-01T00:00:00Z",
            "ended_at": "2018-02-01T00:00:00Z"
         }
      }]
}

Topic: Extension Analytics

Notifies when a new analytics report (CSV file) is available for an extension. The response mimics the Get Extension Analytics endpoint. This webhook requires the analytics:read:extensions OAuth scope.

hub.topic URL

https://api.twitch.tv/helix/analytics/extensions

Required Query String Parameter

NameTypeDescription
extension_idstringSpecifies the extension whose report data is provided. This is the client ID value assigned to the extension when it is created.

Example hub.topic URL

Get notified of analytics data for extension abcd: https://api.twitch.tv/helix/analytics?extension_id=abcd

Example Notification Payload

{
  "data": [
     {
        "extension_id": "abcd",
        "URL": "https://twitch-piper-reports.s3-us-west-2.amazonaws.com/dynamic/WoW%20Armory_overview_v1_2018-04-30_2018-07-29_fb3931c6-4081-44cd-9991-530d83f492ce.csv?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAI7LAMHO6AIVYE6KQ%2F20180731%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20180731T201540Z&X-Amz-Expires=60&X-Amz-Security-Token=FQoDYXdzEDMaDObdwyOVISdo6feHSSK3A9R9gMFeS5zuycuZaBk4tJemqCIazhsQJrpsehBoOufaQkCxrb8RD3oU0xC5pWrZe9kN%2BnezIoLOgTtFRAqTzdIr7J5iUOxGFyKN9XmrmUHGexFfALvoPQWUJNbxoFU6shajSmO3sPK2GnuEaGmIrAqjKrim8saLHDV%2FdSi2ZH3fFx6sBQEGv13Lx0zua7AsvaL%2BSfhIAcOazWjYLMU5N9bxXmaN7IAIF4UjNPqbg07RMWW70hm0edH0RPi%2Fw00faeeSvmreHq6c1C1Lu8a7AysMb0pEGBT7VxmuGmWsXyjLWZ6oNgbx88HXoMJpmAn5Y1hUu7VzOaa84T%2BmCF5Sbn7hbB1xIiPdzaVQ%2Bd85sy4ln09h7dgKh6GFE1VTas2v7RJU1lyD%2FZ%2FWKBwV5Ol8GEGrF1pme8mSBpPGUAJ4vxjLmrGL7ctty%2F0vXke3PyD%2B4%2FtHZ67xaw0y8EKrau23Xvt3blkcDNoQYOfcS%2FqbaK%2BHpyVq4bIBtQq%2BHYU5MuFkgEuwSe5zPDle1ysKSN11B6B6Sy7Httrq542OONS%2BfURkczMbKSPEShddN32Y9VUqKYdUo%2FsWVQQoy7uC2wU%3D&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%22WoW%20Armory_overview_v1_2018-04-30_2018-07-29.csv%22&X-Amz-Signature=736632c7518e841d3a96a5070748ae4df8333cbbf5fd8951144a4610afac3d25",
        "type": "overview_v1",
        "date_range": {
           "started_at": "2018-04-30T00:00:00Z",
           "ended_at": "2018-07-29T00:00:00Z"
        }
     }
  ]
}

Example Of Webhook Flow

Request

This subscribes to the event, user 1337 has a new follower.

curl -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-H 'Content-Type: application/json' \
-X POST -d '{"hub.mode":"subscribe",
"hub.topic":"https://api.twitch.tv/helix/users/follows?first=1&to_id=1337",
"hub.callback":"https://yourwebsite.com/path/to/callback/handler",
"hub.lease_seconds":"864000",
"hub.secret":"s3cRe7"}' \
https://api.twitch.tv/helix/webhooks/hub

Response

202 Accepted

Subscription Verify Request (from Twitch to Client)

GET https://yourwebsite.com/path/to/callback/handler? \
hub.mode=subscribe& \
hub.topic=https://api.twitch.tv/helix/users/follows?first=1&to_id=1337& \
hub.lease_seconds=864000& \
hub.challenge=HzSGH_h04Cgl6VbDJm7IyXSNSlrhaLvBi9eft3bw

Subscription Verify Response

HzSGH_h04Cgl6VbDJm7IyXSNSlrhaLvBi9eft3bw

Subscription Denied Request (from Twitch to Client)

GET https://yourwebsite.com/path/to/callback/handler? \
hub.mode=denied& \
hub.topic=https://api.twitch.tv/helix/users/follows?first=1&to_id=1337& \
hub.reason=unauthorized

Subscription Denied Response

200 OK