Warzone custom API command

Hey there!

I’ve been looking for a command for my nightbot, which will output my warzone stats. Or maybe even some specific stats like KD, total kills, total suicides, total deaths, total top 10’s and so on.
I’m already using commands like this, for both Counter Strike and League of Legens :smiley:

Url with the stats I want to showcase - https://cod.tracker.gg/warzone/profile/battlenet/HotteTove%232682/overview

1 Like

Hiya, have you looked at: Custom API Warzone stats tracker help

Yep, and I didn’t find it helpfull though :smiley:

Hey @HotteTove!

I mean, the command I wrote in that thread already gives the total kills and the kill/death ratio for the user who requested help at the time, you can easily edit it for you and expand it to your needs.
Do you need help for this?

1 Like

Yes, I would be very thankful if you could help me with that :smiley:

I’m looking for: kd, total kills, total deaths, total suicides, total wins, and maybe top kills in 1 game :slight_smile:

:warning: The API blocked requests from Nightbot, the command is dead. :warning:

Alright, after some quick tests, you were right to open a new thread about this, because since you use different services, the URL to get your data is relatively different.
And they just edited their post so people can’t use it to get help anymore, great…

Here’s the URL to your data:

https://api.tracker.gg/api/v2/warzone/standard/profile/battlenet/HotteTove%232682/

And here’s the URL to the data of the other post that’s linked above:

https://api.tracker.gg/api/v2/warzone/standard/profile/atvi/Sanoozle%233011952/

The main differences are that your discriminator—what comes after the # (%23 when URL encoded)—is shorter, and that you’re on battlenet when they’re on atvi. We can see these differences in the profile URLs.


So here’s your command:

$(eval s=$(urlfetch json https://api.tracker.gg/api/v2/warzone/standard/profile/battlenet/HotteTove%232682/).data.segments[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}`)

It has the total wins, kills, deaths, and kills/deaths ratio, there’s no data regarding suicides or top kills in one game inside the API.

1 Like

However, it still seems that it wont work :sweat_smile: It gives me the " Nightbot

: Unexpected identifier" error :roll_eyes:

It was working when I posted the command, and I just checked, the API says that your profile data is private, so make it public again for the command to work.

2 Likes

That solved everythig, thanks for the continuously help :smiley:

1 Like

Hi, could you help me by telling me what part of the code should I change to show my statistics? and from what page are they getting the information?

:warning: The API blocked requests from Nightbot, the command is dead. :warning:

Hey @Rapo84!

Sure!

Go there and look for your profile, make sure you selected the right platform.
Once you found it, your URL will look like this:

https://cod.tracker.gg/warzone/profile/PLATFORM/USERNAME/overview

In the command replace the PLATFORM and USERNAME value by yours according to the link above:

$(eval s=$(urlfetch json https://api.tracker.gg/api/v2/warzone/standard/profile/PLATFORM/USERNAME/).data.segments[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}`)

If you want the warzone lifetime overview data of your profile keep using segments[0], if you want only the battle royale data use segments[1], and if you want only the DMZ/Plunder data use segments[2].

You might need to change more things than that later in the code if you want to access new/different data, use VARIABLE=s.FIELD_NAME.value, give VARIABLE a fitting name and replace FIELD_NAME by an existing one.
Here’s a link that’ll help format the JSON in a readable way, that’ll help to look for the available FIELD_NAMES, the link to use is the one in the $(urlfetch) variable after editing it to get your data.

After that you’re good to go!

If you experience any issue, before making a new post, make sure your profile is public, not private.

1 Like

Hello, first I’d like to say thanks for the help you provide to those of us who are not coders or familiar with the entire concept. I have a couple questions about how these commands work. Do these just get added to nightbot? Also, is it possible to have one that can display random viewers of a stream, (as in, any viewer can type in the command prompt and have their stats displayed?) on demand?

:warning: The API blocked requests from Nightbot, the command is dead. :warning:

Hey @xkajonx!

Not sure what your first question is about? You add this command to Nightbot yourself, it goes into custom commands.

To your second question, yes, it’s possible, however people will have to give their PLATFORM and USERNAME as the website formats it, so let’s say your username is ABCD but you also have a discriminator (numbers after the name), and you play on PlayStation, then you’d have to type psn ABCD#1234 after the command.

The possible values for the platform are:
• PlayStation Network: psn
• Activision ID: atvi
• Battle.⁣net: battlenet
• Xbox Live: xbl

You will also need to use 2 commands, one of which will be an alias called by the first command, so let’s say you call your command !stats, I recommend calling the alias _stats. If you add the commands from the dashboard, make sure to add _stats in the alias field of !stats, if you add the commands from the chat go like this:
!addcom !stats -a=_stats COMMAND_CODE
!addcom _stats COMMAND_CODE

Below are the commands in order, so you have the alias in second:

$(eval `$(querystring)`.toLowerCase().replace(`%20`,`/`))

$(eval s=$(urlfetch json https://api.tracker.gg/api/v2/warzone/standard/profile/$(query)).data.segments[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}`)
1 Like

muchisimas gracias ! thx a lots for your help

1 Like

Emily, thank you very much for your reply. My first question was asking if you (me) would just add the whole text into a nightbot command, I really don’t understand how it all works. I think it would be cool to be able to have viewers query their own stats during my streams. I do play warzone sometimes, but I mainly play Cold War multiplayer these days. I appreciate you typing that all out, but I don’t have a clue what I would need to add to that or change. I feel like I should take a class or something to be able to understand this and how to write it all up.

:warning: The API blocked requests from Nightbot, the command is dead. :warning:

Oh okay, alright, let’s go through a quick course then! :wink:

To add a command you have two options, through the dashboard, or through your chat.


Let’s start with the dashboard:

  • First, use the Command field to give the command a name, add the prefix if you wish to have one, the ! (exclamation mark) is often used.
  • Then fill the command response in the Message field, it can be just text, or JS code inside an $(eval) variable which will generate a text output.
  • If you want to restrict the command to be used by specific users, use the Userlevel field.
  • If you want the command to have a general cooldown (not an user-cooldown), use the Cooldown field.
  • And finally, if you need it, there’s an Alias field, it’s basically a command called right after the one you called. It won’t post the output of both commands, this is a common misconception, it took me a while to understand them. The alias command takes in input the output of the first command thanks to $(query). It’s particularly useful when dealing with conditional $(urlfetch) or if you need to format the input given to a command before sending it to the $(urlfetch) (which is what I did above) because Nightbot fetches the URL before executing the code.

To add commands through the chat, follow the following syntax:

!addcom !commandName -ul=userlevel -cd=cooldown -a=!aliasCommandName commandResponse or commandCode

-ul=, -cd=, and -a= are all optional.

You can also edit or delete a command through your chat with respectively:

!editcom !commandName -ul=userlevel -cd=cooldown -a=!aliasCommandName commandResponse or commandCode
!delcom !commandName

You can’t rename or fetch the command code through the chat though.


You can find all this in the documentation:
!commands
variables


Hopefully that helps you understand how to use the bit of code I gave you, feel free to ask for confirmation if you want to make sure you understood properly. I don’t want to feed it to you though, it’s a good occasion to learn.

Emily, I tried to figure it out, I really appreciate you trying to help me, but I just can’t figure it out. Thank you very much for trying!

:warning: The API blocked requests from Nightbot, the command is dead. :warning:

Alrighty, I’ll make it very simple for you then, but please take the time to try to understand, I can’t make it simpler than this, it’s the simplest thing ever and you won’t be spoon-fed about this again, that said an example never hurts.


Just copy/paste this in your chat, press enter to send the message:

!addcom !stats -a=_stats $(eval `$(querystring)`.toLowerCase().replace(`%20`,`/`))

And then do the same thing with this:

!addcom _stats $(eval s=$(urlfetch json https://api.tracker.gg/api/v2/warzone/standard/profile/$(query)).data.segments[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}`)

Here’s how to set it up from your dashboard, press Submit to add the commands (one by one):


Then to use the command type: !stats battlenet xkajonx#12345 for example.

1 Like

I will work on this tonight, I really appreciate your help. Sorry for any trouble.

1 Like

I’m sorry if I made it seem like I didn’t know how to add commands in nightbot, my issues were how to write the code. I thought I was going to have to know how you were typing all of that out. I tried editing that to have the command retrieve Cold War stats and add the best killstreak value, but came back as Cannot read property ‘value’ of undefined. I tried to edit it like this:
!editcom _stats $(eval s=$(urlfetch json CAN’T POST LINK/api/v2/cold-war/standard/profile/$(query)).data.segments[0].stats; r=s.kdRatio.value; k=s.kills.value; d=s.deaths.value; w=s.wins.value; s=s.streak.value; Wins: ${w} | Kills: ${k} | Deaths: ${d} | Kills/Deaths Ratio: ${r} |Best Streak: ${s})

I don’t know where I went wrong. Can you fill me in please?

I reached the limit on replies, so I’m editing this one in hopes you’ll see it.

Emily, so the confusion here is that I was trying to edit the command FROM Warzone to Cold War, which is the new title of CoD. In trackker.gg, it shows a stat for best killstreak in Cold War. I thought I could edit the command that you made for Warzone to allow me to query stats on Cold War, but it did not work. I’m not sure what edits I should have made to make it work for Cold War stats.

1 Like