Using eval and urlfetch to print result from OWAPI

I want to retrieve the competitive rank using the Overwatch API.

This is how I’m editing the command:

!editcom !rank $(eval response =$(urlfetch;

For some reason, I keep getting the following response from NightBot when I try the command.

Nightbot: Cannot read property 'stats' of undefined

When I navigate to in my browser, I correctly get data in the .us attribute of the object, so that’s why I’m confused about the error message from the Nightbot.

Can anyone let me know what I’m doing wrong?

The problem is that $(urlfetch is being replaced with [Response must be less than 400 characters]. This is because Nightbot doesn’t allow the standard $(urlfetch ...) to fetch more than 400 characters. You can, however, use $(urlfetch json ...) to fetch any amount of characters.

It is also good practice, but not necessary, to use JSON.parse on a JSON string rather than inserting JSON directly into your JavaScript code.

Also, I visited that URL, and us.stats.competitive.overall_stats.comprank was null, so I made the command check for that and say “None” instead of “null”.

Fixed version:

!editcom !rank $(eval response = `$(urlfetch json`; try {json = JSON.parse(response); compRank =; compRank == null ? "None" : compRank} catch(e){`${e}: ${response}`.substr(0, 400)})

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