Somehow i cant confirm Subscriptions for webhooks

await request({
    url: 'https://api.twitch.tv/helix/webhooks/hub',
    method: 'POST',
    headers: {
        'Client-ID': "<clientid>",
        'Content-Type': 'application/json',
        'Authorization':'Bearer '+<token>
    },
    form: {
        'hub.callback': 'https://<ngrok things>.ngrok.io/twitch/webhook',
        'hub.mode': 'subscribe',
        'hub.topic': 'https://api.twitch.tv/helix/users/follows?first=1&to_id=<channelid>',
        'hub.lease_seconds': 864000,
        'hub.secret': "<secret>"
    },
    json: true
}, (err, res, body) => {
    if(err) console.log(err)

    //console.log(res)

This is my subscription request

app.get('/twitch/webhook', (req, res) => {
// confirms subscription
console.log(req.query["hub.challenge"]," challange code")
res.writeHead(200, {'Content-Type': 'text/plain'});
res.send(req.query['hub.challange']) 
});

Im sending the hub.challange back with text/plain header ( i try it without header too ) but when i check my subscriptions its “0” whats wrong also i cant get POST request’s from webhooks too

  1. Consider moving from request, request is deprecated

  2. You mis spelled challenge in your req.query call to res.send

Should be

res.send(req.query['hub.challenge'])

https://github.com/BarryCarlyon/twitch_misc/blob/master/webhooks/handlers/nodejs/receive.js#L63

You can just do

res.send(req.query['hub.challenge']);

No need to faff with headers

  1. You won’t get any posts until you confirm the subscriptions

  2. Did your code log the incoming get request and/or did ngrok log it? It’s possible that you hit the ngrok limits. So ngrok is ok for spot tests but best avoided after that

Yes its working rn thanks, and i dont understand why challenge works instead of “challange” cause im getting an token at console.log(req.query["hub.challenge"]," challange code")

console.log(req.query["hub.challenge"]," challange code")

Outputs the challenge from the query string then outputs the raw word of “challange” which is misspelt as well.

So the first part of the console log is correct.

You typoed the actual res.send

I see it rn, how stupid i am :frowning: how can i close this thread

S’all good and picking a solution basically does that!

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