Your POST call is wrong.
First:
‘hub.callback’: ‘dangerrdoom.tv/api’,
Should be:
‘hub.callback’: ‘https://dangerrdoom.tv/api’,
You are missing a protocol (either http or https)
Second:
As per the node-fetch docs node-fetch - npm
fetch('http://httpbin.org/post', {
method: 'POST',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' },
})
.then(res => res.json())
.then(json => console.log(json));
Your fetch call should be
fetch(BaseURL + 'webhooks/hub',{
method :'POST',
headers : {
'Client-ID': Settings.twitchClientID,
'Content-Type': 'application/json'
},
body : JSON.stringify({
'hub.mode': 'subscribe',
'hub.callback': 'https://dangerrdoom.tv/api',
'hub.topic': BaseURL + 'streams?user_id='+ userID
})
})
.then(res => res.text())
.then(body => console.log(body));
You were posting as plain instead of as JSON
You should revise your .then’s to check the HTTP Response code, as you get a 202 on success.
Whats the raw body response say?
Also consider the following for your userID fetch call
fetch('SOMEUR:', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then((response) => {
return response.json();
}).then((json) => {
console.log(json);
console.log('All done');
}).catch(function(ex) {
console.log('parse error ', ex);
});
Fetch can do the JSON parsing for you and error out accordingly
I think your res.text()
is messing up. I don’t use node-fetch too much myself, I prefer request
Finally, node-fetch - npm is all well and good, you might get better mileage out of GitHub - request/request: 🏊🏾 Simplified HTTP request client.