Question about a warzone custom API command

Hi there!

I mod a few channels on twitch and stumbled upon a thread on Nightdev community where someone needed help fetching data from the COD tracker API. The thread I’m referring to is this: Warzone custom API command - #4 by EmilyPerrimon

I really love it, but it seems it fetches data from plunder and battle royale combined. I’d like to only display the values on Battle Royale, but I can’t figure out how to filter through these results as they all have the same tags (like kdRatio is displayed 3 times). Since I’d like to implement this command for the #1 NA kills player, it’s important it only shows the value of kills, deaths and KD from Battle Royale, not including plunder. this shows you the values combined (the first value highlighted) and the 2nd value which we want to display. From what I’ve seen, the only difference is this part which is in the code before it shows the 2nd value:

{“type”:“mode”,“attributes”:{“mode”:“br”},“metadata”:{“name”:“Battle Royale”}

which obviously refers to the Battle Royale value.

I have no clue how to get the 2nd result, as the command will only display the first result. Is anyone able to help me out on this matter?

The command used (copied from the thread link above, adjusted to match one of the streamers I mod for) is:

$(eval s=$(urlfetch json[0].stats; r=s.kdRatio.value; k=s.kills.value; d=s.deaths.value; w=s.wins.value; Wins: ${w} | Kills: ${k} | Deaths: ${d} | Kills/Deaths Ratio: ${r})

Thanks in advance!

use data.segments[1] instead of data.segments[0]. I believe


this fixed it, thank you so much.

1 Like

Actually there is still a problem; the command seems to only work for modded users, not for subs or followers. Command is not on mod only. It returns an unexpected identifier error when used by a non-mod. Any ideas?

Hey @lurkaccino!

If the command isn’t mod-only, non-mods should be able to use it as well, there’s nothing in the code that restricts anyone to use the command.
It’s possible however an error occurred when you created the command and it considers the command to be mod-only while displaying it as available to everyone, it already happened.
I would suggest editing the command like this:

!editcom !command_name -ul=everyone

If it doesn’t work, delete the command and create it again.
If it still doesn’t work let me know, I’ll see what we can do.

Thank you @heskeylane for the solution, that’s exactly what I would have said!

1 Like

This worked like a charm, thanks Emily.

I was wondering if these stats can also display daily stats, not just lifetime and weekly stats.
I know there’s an option on the COD tracker website, I just don’t see the data in the API.

Hmm, I can’t even find the option to display the daily stats, so I don’t know… Do you have a link, or can you explain me how I’d reach the daily data? If I can load the page I might be able to find the API link matching with the data.

This is the data I was referring to:

Yes, there we go!

This is your original link:

And that’s the link to use to have the “daily data”, aka the last 20 matches:

So basically we replace standard/profile/ with matches/.

We can’t easily access data past the last 20 matches as the URL is unpredictable after that, and that’d involve combining more than one source, not knowing when to stop fetching, this is just a bad idea, so if you do more than 20 matches in a day, the data of the oldest ones won’t be taken in account, sorry.

Then for the code it’s a bit more complicated than just reading it this time…

//fetch matches data
m=$(urlfetch json;
//initiate variables
//for each match
  //access stats
  //add the kills to k, the deaths to d
  //add each ratio to r, r will be the sum of all ratio from all matches, will fix that later
  //push each placement value to an array
//for each placement, if #1, add a win
//output, sum of all ratio divided by number of matches, then rounded to two decimals
`Wins: ${w} | Kills: ${k} | Deaths: ${d} | Kills/Deaths Ratio: ${Math.round((r/m.length)*100)/100}`;
$(eval m=$(urlfetch json;k=d=r=w=0;p=[];for(i=0;i<m.length;i++){s=m[i].segments[0].stats;k+=s.kills.value;d+=s.deaths.value;r+=s.kdRatio.value;p.push(s.placement.value);}p.forEach(e=>e==1?w++:``);`Wins: ${w} | Kills: ${k} | Deaths: ${d} | Kills/Deaths Ratio: ${Math.round((r/m.length)*100)/100}`;)

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