NightDev Community Forums

Issue running nightbot command get API


I am having issues running the following command to my twitch nightbot.

$(eval a = $(urlfetch json$(query)); js = JSON.parse(a); Player Name: ${js.player_name} | Rank: ${js.rank} | Wins: ${js.wins} | Losses: ${js.losses} | Points: ${js.points})

Result is

Player Name: undefined | Rank: undefined | Wins: undefined | Losses: undefined | Points: undefined

Why is this undefined?

Hey @mastermick888!

Can you give us your username in the game so we can have a look at what the API looks like.
We can’t be of much help otherwise.

@EmilyPerrimon sorry i forgot to add that, try user WarMachine which should return


Hiya. The API returns an array, with possibly multiple players… but js[0].player_name should work.

Thanks @xgerhard this seems to work, I totally forgot that it returns a list object. So if I wanted to iterate through the results and display ALL, what is the nightbot command to do a foreach loop?


$(eval a = $(urlfetch json$(query)); js = JSON.parse(a); for i in js: Player Name: ${i.player_name} | Rank: ${i.rank} | Wins: ${i.wins} | Losses: ${i.losses} | Points: ${i.points})

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