Tutorial to create Custom API?

Sorry if this is a stupid question but I want to try to do some custom API but I have no idea how…
Is there some documentation online that gives a little hindsight about where to start?

I tried to use that https://api-docs.nightbot.tv/#basic-steps
but when I’m on the nightbot site I have no idea where to create the API, when it ask for links, etc…

Heya, I’m not sure what exactly you mean, looks like you’re confusing 2 different things. Custom API gives access to external sources through Nightbot commands. The page you’re linking to is the Nightbot API, an API to manage Nightbot from an external app.

If you’re refering to Custom API commands, heres a bit info:
The thing the Nightbot Custom API does is displaying the plain text content of the url you give. So the thing you should learn is a server side programming language and have access to a place where you can host your files.

Simple PHP example:

<?php
echo 'Hi';
?>

Command:
!commands add !hi $(urlfetch https://example.com/hi.php)

Output:
xgerhard: !hi
Nightbot: Hi


If you are familiar with PHP, you can use Nightbot variables to create interactive scripts.

PHP example:

<?php
if(isset($_GET['query']))
{
    $strQuery = strtolower(trim(urldecode($_GET['query'])));
    switch($strQuery)
    {
        case 'random':
			echo rand(5, 15);
		break;
		
		default:
		case 'greet':
			echo 'Hello';
		break;
	}
}
?>

Command:
!commands add !hi $(urlfetch https://example.com/hi.php?query=$(querystring))

Output:
xgerhard: !hi random
Nightbot: 11
xgerhard: !hi greet
Nightbot: Hello

With those variables you can create scripts as complex as you want. Hope this helps.

3 Likes

Oooh Wow!

Yes that was totally what I meant, thanks I lot. I don’t have any knowledge yet about server side/php coding but at least now I know that’s what I need to look into.

Thanks a lot!

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