Hi there, initially i wanted to build a command that returns the how many commands a channel has. Since this functionality is not provided natively i figured i could make use of UrlFetch. Checking the Commandpage for a given Channel in Chromes Inspector revealed that a request like this is needed:
curl ‘https://api.nightbot.tv/1/commands’ -H ‘nightbot-channel: 5c7288c4cc39145dcc8b5ebe’
5c7288c4cc39145dcc8b5ebe being my nightbot-channel-id
I quickly discovered, that UrlFetch does not have support for manually set headers.
I’m not a JS person but figured this could surely be done with the help of eval() which Nightbot supports.
I got things down to an ajax request in the style of:
$.ajax({
type : “GET”,
url : “https://api.nightbot.tv/1/commands”,
beforeSend: function(xhr){xhr.setRequestHeader(‘nightbot-channel’, ‘5c7288c4cc39145dcc8b5ebe’);},
success : function(result) {
console.log(result._total)
}
})
which i call from a pastebin through like so:
$(eval ‘$(urlfetch https://pastebin.com/raw/carvKLj4)’)
i guess the issue here is some escaping or that ajax simply won’t work with however eval() is implemented within Nightbot. It would be great if someone could help me figure out where my oversight is as i’m absolutely new to Javascript and Webdevelopment really isn’t my strong suit.
For this specific project i would be happy to just get the number of commands displayed, but in general i’d be more interested in being able to send Headers with my requests as these are mandatory with many APIs.