How do i put a javascript variable in $(urlfetch) url

I currently have this command:
$(eval
if(1==1){var code = “code1”;}else{var code = “code2”;}
var json = $(urlfetch json http://speedrun.com/api/v1/leaderboards/twwhd/category/ code variable here ?top=1&embed=players))
To get the current world record from a game.
Is it possible to put the “code” variable in the json url, if so how?

Thanks in advance!

1 Like

You have to nest the eval that calculates the URL part inside the urlfetch.

Know that if you need to use some other Nightbot variable inside the eval that calculates the URL part, you will have to use two commands (one an alias of the other) in order to circumvent the variable nesting limit.

$(eval var json = $(urlfetch json http://speedrun.com/api/v1/leaderboards/twwhd/category/$(eval if(1==1){"code1"}else{"code2"})?top=1&embed=players))
2 Likes

That makes a lot of sense.
Thanks a lot!

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