Funny you bring up that example, as I’ve tried using it, and ended up keeping their hub.topic for later testing.
Seems like trumpi27 found an error, it even gives 202 with that call.
I’ll show updated code, eliminated URL encoding problems, good suggestion.
var request = require('request');
async function hook(){
return new Promise(function(resolve, reject) {
var A =JSON.stringify({"hub.mode":"subscribe",
"hub.topic":"https://api.twitch.tv/helix/users/follows?first=1&to_id=1337",
"hub.callback":"https://www.thehighlighthub.com/SubscribeTwitch",
"hub.lease_seconds":"864000","hub.secret": "s3cRe7"})
request(({ method: 'POST', url: 'https://api.twitch.tv/helix/webhooks/hub?',body: A,
headers: {'Client-ID': '***********',"Content-Type":"application/json"}}),
(err, res, body) => {
err && reject('webhooks failed')
console.log(body)
console.log(JSON.stringify(res));
resolve(res.toJSON().statusCode === 202 ? 'webhook connected' : res.toJSON().statusCode + ' Error: ' + body.message)
})
})
}
hook()
Only difference from your Curl-To-Node JS Requests translation is, instead of json:true in the request argument, the “Content-Type”:“application/json” header was added. Would get status code 400 otherwise. Also changed the hub.topic value to accomodate their required notation.
Edit: Adding the response I’m getting,
{"statusCode":202,"body":"","headers":{"content-length":"0","server":"nginx","access-control-allow-
origin":"*","cache-control":"no-cache, no-store, must-revalidate,
private","expires":"0","pragma":"no-cache","ratelimit-limit":"30","ratelimit-
remaining":"29","ratelimit-
reset":"1530147305","twitch-trace-id":"cb0285c532e52e3b0f06451555d0f96c","x-ctxlog-
logid":"1- 5b3431b0-7b985420fbc32fac9f8a4cf0","timing-allow origin":"https://www.twitch.tv","date":"Thu, 28 Jun 2018 00:54:08 GMT","connection":"close"},"request":{"uri"{"protocol":"https:","slashes":true,"auth":null,"host":"api.twitch.tv","port":443,"hostname":"api.twitch.tv","hash":null,"search":"?","query":"","pathname":"/helix/webhooks/hub","path":"/helix/webhooks/hub?","href":"https://api.twitch.tv/helix/webhooks/hub?"},"method":"POST","headers":{"Client-ID":"***********","Content-Type":"application/json","content-length":211}}}