Webhook subscriptions failing

I am trying to establish a webhook subscription to the streams endpoint in node.js. the application is receiving the GET request with the hub.challenge after making the subscribe request but no matter what I try I can’t get the subscription to be compleated. This is my current code for creating the hub.challenge callback


app.get("/twitchhook", (req, res) => {

app.post("/twitchhook", (req, res) => {

and if simulate a get request with a hub.challenge query in the browser or using postman I can see the site displaying the test hub.challenge.

I have tried everything I could think of so far so any ideas would be appreciated.

Can you show your subscription create request?

Assuming this is express it looks correct as it matches my example here

It is an express server indeed, the subscription create request looks like this

fetch('https://api.twitch.tv/helix/webhooks/hub', {
            method: 'POST',
            headers: {
                'Client-ID': config.twitchID,
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${data.access_token}`
            body: JSON.stringify({
                'hub.mode': 'subscribe',
                'hub.topic': `https://api.twitch.tv/helix/streams?user_id=${config.streamerID}`,
                'hub.callback': 'http:// "My callback url" :3000/twitchhook',
                'hub.lease_seconds': '864000'
        .then(res => res.json())
        .then(json => console.log(json));

the subscription create request seems fine to me as I do receive a GET request from twitch but at this point I’m convinced it could be anything

And when you make that request, your server is logging an inbound GET request?

Then are you using

To check/confirm the subscription stuck?

I do receive an inbound get request, although not every time, and I have been using the webhooks/subscriptions endpoint through postman (using the same OAuth token and client ID) to see if the subscription stuck, but it always return 0 subscriptions

Ok I managed to get it working…

turns out it was just me not paying attention and being stupid (like usual ). On closer inspection the inbound requests that I was getting were all unsubscribe requests.

This was because me thinking the reason I did not get new requests after a bit was due to accidentally subscribing to the same topic too many times and there for sending unsubscribe requests via postman.

Turns out my subscribe create request was correct but the code around it to read the file I stored the token in was not, which made it not run. After fixing that code and running it again I now received a subscribe inbound request, and the webhooks/subscriptions endpoint shows a subscription.

Thanks for the replies and for your time, and sorry for wasting it a bit…

all good, we all need a rubber duck sometimes!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.