Export your Nightbot commands to save them on your computer!

If you wish to have a backup of your commands on your machine, you can use the API to export them.

  1. Go to your Nightbot Applications and create a new one.
    Give it a name so you know what it is, there’s no need for a redirect URI.
    Click on Submit.

  2. Once created, click on the Edit button (the yellow pencil icon under Actions).
    There copy the Client ID and the Client Secret and save them somewhere safe.
    Never share your Client Secret!
    If you don’t have a Client Secret, click on the New Secret button.


You now have everything you need to obtain your access token.

  1. To obtain your access token, open the command prompt and paste the following cURL command:

    curl -X POST "https://api.nightbot.tv/oauth2/token" -d "client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=client_credentials&scope=commands"
    

    Don’t forget to replace CLIENT_ID and CLIENT_SECRET with the information you saved earlier.

    Press Enter and you should get an answer that looks like this:

    {"access_token":"ACCESS_TOKEN","token_type":"bearer","expires_in":2592000,"refresh_token":"REFRESH_TOKEN","scope":"commands"}
    

    What we’re interested here is the Access Token, save it along the Client ID and Client Secret.
    Never share your Access Token either!


    To access the command prompt on Windows, press the Windows + R keys, type cmd in the dialogue and press Enter.
    On OSX or Linux, just open a terminal.


    Please note that the Access Token lasts 30 days, but you can refresh it with the Refresh Token that lasts 60 days with the following cURL command:

    curl -X POST "https://api.nightbot.tv/oauth2/token" -d "client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=refresh_token&refresh_token=REFRESH_TOKEN"
    

    It’ll answer you with new ACCESS_TOKEN and REFRESH_TOKEN.


Finally, let’s get our commands!

  1. On the command prompt, paste the following cURL command:

    curl -X GET "https://api.nightbot.tv/1/commands" \ -H "Authorization: Bearer ACCESS_TOKEN"
    

    Don’t forget to replace ACCESS_TOKEN with the information you saved earlier.

    Press Enter and you’ll get an answer that looks like this:

    {"_total":5,"commands":[{},{},{},{},{}],"status":200}
    

    Copy the answer and save it in a file, preferably a .json file if you know how to use them.


  1. So the answer is more readable, you can format it using a JSON Formatter.
1 Like