Webhooks Subscription not being created


#1

Greetings!

I am developing in C# utilizing the Azure environment. I have used Postman to help determine proper requests and everything I have appears to be working as expected but when I check the webhooks/subscriptions for what I’ve signed up for… it is empty. Any guidance is appreciated.

My request to subscribe to the user stream event:

POST /helix/webhooks/hub?hub.callback=https://XXXXXX.azurewebsites.net/api/TwitchStreamChange&hub.mode=subscribe&hub.topic=https://api.twitch.tv/helix/streams?user_id=433XXXXXX2&hub.lease_seconds=864000&hub.secret=0XXXXXXXXXXXXXXXXXXXr9g HTTP/1.1
Host: api.twitch.tv
Content-Type: application/json
Authorization: Bearer lpXXXXXXXXXXXXXXXmu

I receive the 202 Accepted response. I then receive an HttpRequest with the hub.challenge:

Request Received
Length: ‘No Length’
Type: ‘No Type’
Has Cookies: ‘0’
Has Headers: ‘16’
Method: ‘GET’
Scheme: ‘https’
Route: ‘0’
QueryString: ‘?hub.challenge=__k2XXXXXXXXXXXXXKh5aikw&hub.lease_seconds=864000&hub.mode=subscribe&hub.topic=https%3A%2F%2Fapi.twitch.tv%2Fhelix%2Fstreams%3Fuser_id%3D43XXXXXX2’
Body: ‘’

I send the pingback and get the following response:

Response Content: {“data”:[],“pagination”:{}}
StatusCode: ‘OK’
Phrase: ‘OK’

** Response - HttpRequestMessage **

  • Method: GET
  • RequestUri.AbsoluteUri: https://api.twitch.tv/helix/streams?user_id=43XXXXX2&hub.challenge=__k2mmXXXXXXXXXXXXXXXXFbR1Kh5aikw
  • Version.Build: -1
  • Request Headers:
    – Key: ’ Host ’ Values: ’ api.twitch.tv
    – Key: ’ Authorization ’ Values: ’ Bearer lXXXXXXXXXX8epmu
    – Key: ’ Request-Context ’ Values: ’ appId=cid-v1:2848c979-7c50-4120-92ea-f281001fd7b6
    – Key: ’ Request-Id ’ Values: ’ |a313deb27b162e498561e44598981997.1a51eba9e1c26b47.
    – Key: ’ traceparent ’ Values: ’ 00-a313deb27b162e498561e44598981997-1a51eba9e1c26b47-00
  • Content Headers:
    – Key: ’ Content-Type ’ Values: ’ text/plain; charset=utf-8
    – Key: ’ Content-Length ’ Values: ’ 109

If I try a “live” user the data payload is populated. The user in the example just happens to be offline…

When I check for the webhook I get an empty payload.

{
“total”: 0,
“data”: [],
“pagination”: {}
}

Everything appears to be working per the ‘New Twitch API’ Webhooks Guide and Reference. Is there anything I am missing or can try to get my Stream Event subscription to stick?

Thanks

Mark


#2

You seem to be sending your subscription request as querystring params, where as the docs https://dev.twitch.tv/docs/api/webhooks-reference specify that they should be sent in the request body.

What specifically are you sending back? You should be responding with the hub.challenge, a 200 status code, and nothing else.


#3

Thanks for getting back

I have modified the sub request:

POST /helix/webhooks/hub HTTP/1.1
Host: api.twitch.tv
Content-Type: application/json
Authorization: Bearer lpXXXXpmu

{
	"hub.callback":"https://tgXXXXns.azurewebsites.net/api/TwitchStreamChange",
	"hub.mode":"subscribe",
	"hub.topic":"https://api.twitch.tv/helix/streams?user_id=43XXXX2",
	"hub.lease_seconds":"864000",
	"hub.secret":"0XXXXr9g"
}

202 Accepted Received

I am sending the following and get back the top 20 live and the pagination. If I provide the user_id as a querystring parameter it will return just the streamer payload if they are live or an empty one if they are not. Should I send the user_id or does that not matter?

GET /helix/streams?hub.challenge=MIFpXXXXgCwGiFBatkS7 HTTP/1.1
Host: api.twitch.tv
Content-Type: text/plain
Authorization: Bearer lp1XXXXay8epmu

I still have an empty sub list:

{
“total”: 0,
“data”: [],
“pagination”: {}
}


#4

are you just echoing back the challenge? if yes C# may automatically format it as json and put it in quotes which is bad.

modify the Content-Type of the returned response to be text/plain or text/html to prevent that.
thats what I came across at least with asp.net core.


#5

The GET in my second post is from Postman… The challenge code is sent as a query string as @Dist suggested. C# is the same format.

It should be noted that I receive the payload after I send the challenge back. I’m assuming, of course, that the payload means the api received the challenge successfully.


#6

You’re doing the verification step wrong.

When Twitch sends a GET request to your callback URL, containing a hub.challenge, your server needs to respond to that request from Twitch by returning the hub.challenge in the body.

You don’t send it as a querystring on anything, you don’t need to make any more requests yourself, you simply respond to Twitch’s GET request to you with the challenge in the body. If Twitch doesn’t get back JUST the hub.challenge and a 200 response when it sends a GET request to your callback URL, it assumes either the callback url isn’t accessible, or isn’t set up to handle webhooks, and so the subscription process fails.


#7

@Dist thanks for circling back on that. I was able to create a response to the request. Everything is working as expected now.