NightDev Community Forums

Using urlfetch results to populate a second urlfetch


Currently, I’m looking up Apex Legends stats for a single hard-coded user using the following command that I borrowed from reddit, specific ApexID(aid) redacted:

!commands add !apexstats $(eval var apex=$(urlfetch json aid=1337deadbeef); ('Name: ’ + + ’ - Legend: ’ + apex.legend + ’ - Kills: ’ + apex.kills + ’ - Level: ’ + apex.level))

The same reddit thread has you grab this “aid” using another GET which also returns a json, which I’ve implemented accepting an argument as follows:

!commands add !apexlookup $(urlfetch json$(1))

Where the argument $(1) would be 1337_player, or whatever your PSN handle is.

The former returns nicely formatted (for twitch) text, where the second is an ugly pure json.
My previous experience in coding is Java, Python, Bash, and Powershell, so I will admit to not knowing JS or messing much with nightbot’s syntax.
I would like to implement a command which returns the first’s nicely formatted text, but which is used by passing the PSN name of interest.

All of my attempts so far at using eval with arguments, or trying to nest them into each other so that the inner command’s output is simply at the end of the aid=, have failed.

Thanks for reading, I know its a lot.



Something like this should work (untested):

!commands add !apexlookup $(eval const {results} =$(urlfetch json$(1)); const result = results && results[0]; result ? `Name: ${} - Legend: ${result.legend} - Kills: ${result.kills} - Level: ${result.level}` : 'No results found')