So I’ve been trying to get a Webhook for subscribing to an event when a streamer gains a follower. I’m able to get Status Code 202 from the initial POST request. I’m not able to get the Subscription Verify Request from twitch to my callback URL. The callback URL is able to receive GET requests. The Client-ID works with many other api requests I’ve used.
I’ve looked at quite a few other’s codes, and multiple forums, haven’t had any success. If anyone would be able to give my code a glance it would be much appreciated!
var request = require('request');
async function hook(){
return new Promise(function(resolve, reject) {
let hub = [
`hub.mode=subscribe`, // subscribe
`hub.callback=https://thehighlighthub.com/SubscribeTwitch`, // this is the url where I
receive the GET and POST from twitch
`hub.lease_seconds=864000`, // 864000
"hub.topic=https://api.twitch.tv/helix/users/follows?to_id=29795919" // stream online
topic = https://api.twitch.tv/helix/streams?user_id=44322889
].join('&')
request(({ method: 'POST', json: true, url: 'https://api.twitch.tv/helix/webhooks/hub?' +
hub, headers: {'Client-ID': '************',
'Content-Type': 'application/json'}}),
(err, res, body) => {
err && reject('webhooks failed')
console.log(body)
resolve(res.toJSON().statusCode === 202 ? 'webhook connected' :
res.toJSON().statusCode + ' Error: ' + body.message)
})
})
}
hook()
Edit: Tidied code.