Apex Tracker Using Node.js

Prerequisites

▸ Knowledge of Terminal or Command Prompt will be very useful as well

▸ This tutorial will be using the Node.js environment for our API pulls and data output. If you don’t have Node.js you can download it from here, This tutorial will assume you know how to install NPM packages and basic node execution if not checkout my other tutorial here

▸ If you have any Javascript experience it will help you phenomenally, if not we are going to be using some of the es6 and a couple of npm packages.

▸ We are going to be using the TRN Apex Tracker API, you will need to sign up and click to generate an API Key. Be sure to save it will will need it later

Making your first pull

▸ To make your first pull, open up your Terminal (linux or mac) or Command Prompt (windows10).

▸ Copy and paste this code:

Explanation

▸ To run through what is happening here:

curl - is a command-line tool for getting or sending data including files using URL syntax.

(If you are looking for more commands for cURL type “curl — help”)

◈ The API Url - This is the endpoint for which when we go to that address link the server will send us a JSON formatted page with the data we queried for

◈ In the API Url you will see two sections listed — {SystemNumber} and — {Username}, here for the System number it will depend on what system or console you are playing on if you are using a:
◊Xbox you will put: 1
◊PSN you will put: 2
◊PC you will put: 5

▸For your Username type in your connected Xbox Live, PSN, or Origin Username depending on your system type

-H - This is the Header command in which we will pass our API Key through

◈ API Key - This is the key that the servers uses when you make a request to validate you are a a registered user on the page and not just simply a random person making a ton of requests

Running The Code

▸ If you have all of that entered, hit enter and you should get a very long list of multiple different words and numbers like so:

▸ If you are seeing this, your good to go onto the next part if not go back through the explanation and re-read to see if you missed something.

Hooking it up with Node.js

▸ Congrats, you’ve made it this far! The next step is to code it in Node.js, but first we need to go over the fact that if we make a GET request in Node it will return a Error 301, which is a “Location has been moved” error. This is because Cloud-flare is protecting from DDos by making you connect and making you redirect through another redirect URL. However Node.js doesn’t currently do this, to get around this we will use a clever NPM packet that will redirect it until it hit the endpoint of the page.

▸ Here isthe NPM packet you will need for this project:

$ npm install -g follow-redirects

▸ We can then import them like so:

var https = require('follow-redirects').https;

The Code
Extras

▸ If you’re looking for more specific data you can access the data through the dot notation ie. console.log(json.data.children[0].metadata.legend_name);

▸ I am currently using this for our Discord bot using the Discord.js Framework to display player’s stats, if you want to create a system for displaying data just have a user input their system and name and display it to them