Hub.mode is required?

I got some help for an issue I had last night and I am not sure if I should just continue to post in that topic or start a new one. If I need to delete this and update the other please let me know.

My new issue is as the title says I am getting hub.mode is required but its clearly there on line 3

also its not related to the API but I am trying to get my getUserID to return the results but I keep getting undefined.

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 https://www.npmjs.com/package/node-fetch

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, https://www.npmjs.com/package/node-fetch is all well and good, you might get better mileage out of https://github.com/request/request

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