How to use the nightbot custom api

Asked Jul 13, 2020·1 reply·Last activity 6 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hey, I am trying to use the nightbot custom api, but I did not know how to, what I want to do basically is a javascript program which can edit commands, so I can edit the commands through the javascript program, I know javascript and I did some similar things, but I didn't understand any thing in the documentation, can someone tell me where can I start? maybe a small and simple example how to use the api?

1 reply

The docs give examples of sending a request to each API endpoint. Each example tells the required request method, the URL to reach the endpoint, and any necessary headers to include in the request (almost every endpoint requires you to include an access token, see here).

An example of hitting the send channel message endpoint in PHP.

<?php
// Initialize cURL, set URL to "send channel message" endpoint, set POST method,
// set access token header
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.nightbot.tv/1/channel/send");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ACCESS_TOKEN"));
curl_setopt($ch, CURLOPT_POSTFIELDS, "message=Hello World!");
curl_exec($ch);
// Job's done, close the cURL session
curl_close($ch);
?>

An example of hitting the same endpoint in AJAX, copied from my other post.

$.ajax({
url: "https://api.nightbot.tv/1/channel/send",
method: "POST",
headers: {
"Authorization":"Bearer ACCESS_TOKEN",
},
data: "message=Hello World!"
});