How to add json custom api command to Nightbot?

Hi!

So I was trying to figure out how to make a !song command which returns the name of a song from Spotify when the song is from a user’s Local Files.

I managed to figure out the command that works with Phantombot, but I’d like to make it work with Nightbot, but not sure what I need to change.

The command that works with Phantombot is along the lines of:
(customapijson https://api.spotify.com/v1/me/player/currently-playing?access_token=xxx&format=json item.name)

I tried using $(customapi…), but the response is “[Response must be less than 400 characters]”

Many thanks for any help in advance!

1 Like

Here is a simple command without error handling:

$(eval ($(urlfetch json https://api.spotify.com/v1/me/player/currently-playing?access_token=xxx&format=json)).item.name)

Here is a more complicated command that handles errors:

$(eval r=decodeURIComponent("$(querystring $(urlfetch json https://api.spotify.com/v1/me/player/currently-playing?access_token=xxx&format=json))");try{JSON.parse(r).item.name}catch(e){`Failed to parse Spotify API response: ${e.message}: ${r}`.slice(0,400)})
3 Likes

Many thanks, it’s working beautifully! :slight_smile: https://i.imgur.com/308jICB.png

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