NightDev Community Forums

Question about a warzone custom API command

Hi!

I found a command which helps me fetching data from the cod tracker API.
The command is working for KD, weekly KD, kills and a lot of other things, but not for level.
For example

!addcom !wzstats -ul=moderator -a=_wzstats $(eval `$(querystring)`.toLowerCase().replace(`%20`,`/`))
!addcom _wzstats $(eval u=$(urlfetch json https://api.tracker.gg/api/v2/warzone/standard/profile/$(query));s=u.data.segments[1].stats;p=u.data.platformInfo.platformUserHandle; r=s.kdRatio.value; k=s.kills.value; d=s.deaths.value;t=s.weeklyKdRatio.displayValue;h=s.weeklyHeadshotPct.value;`The stats of ${p} are >> Kills: ${k} | Deaths: ${d} | Overall K/D: ${r} | Weekly K/D: ${t} | Headshot: ${h} % | Profile Link >> https://cod.tracker.gg/warzone/profile/$(query)/detailed`)

The command above is working.

But when I try to fetch the level with z=s.level.value , i get the answer "Cannot read property ‘value’ of undefined "

Can someone explain me why?

Hiya, sure I can explain why. In the command you posted, the stats are assigned to var s:

s=u.data.segments[1].stats

The API has the stats divided in 3 sections, 0 = overview, 1 = warzone, 2 = plunder. So currently the variable s, only has access to the warzone section.
The user level is only available in the overview section, so you would need to access it like this:

u.data.segments[0].stats.level.value

or ‘level.displayValue’ whatever you prefer.

2 Likes

hey. ty for the answer! <3