battlefield stats (bf1, bf4)
A node api that allows you to collect, analyze, and serve battlefield 1 and battlefield 4 statistics. This fully
makes use of the battlefield tracker network - https://battlefieldtracker.com/
Quick start
npm install battlefield-stats
const bf = new BattlefieldStats(API_KEY);
const params = { personaId: xxxxxxxxx, platform: bf.Platforms.PC }
bf.Api.request('/Stats/BasicStats', params, responseCallback)
Getting started
Get your API Key from the battlefield tracker network here: https://battlefieldtracker.com/site-api
Install battlefield-stats using npm by running using npm install battlefield-stats
Example
npm install battlefield-stats
const BattlefieldStats = require('battlefield-stats');
const API_KEY = 'YourAPIKeyFromBfTracker'
const bf = new BattlefieldStats(API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YourOriginUserName
}
const route = '/Stats/BasicStats';
bf.Api.request(route, params, (error, response) => {
if (!error && response) {
console.log(response);
}
})
Usage with Express
You can use battlefield-stats-express
which adds hooks and functionality to express middleware with this module.
npm install battlefield-stats-express
const express = require('express');
const battlefieldStats = require('battlefield-stats-express');
const app = express();
const bfs = battlefieldStats(YOUR_API_TOKEN);
app.use('/api', bfs)
app.listen(3000);
Now you can see results when you navigate to http://localhost:3000/api/Stats/DetailedStats?platform=3&displayName=Ravic
For more information see battlefield-stats-express on github.
API Documentation
This API closely follows the REST Api documentation found at http://docs.trnbattlefield.apiary.io/#
Common Parameters
All API calls require platform
and either personaId
or displayName
, and optionally may use the game
parameter.
Platform
All the requests require a platform query parameter.
The following values are allowed: 1 for Xbox, 2 for PlayStation, and 3 for Origin. Alternatively, you can use Platforms.XBOX
, Platforms.PS4
, Platforms.PC
respectively.
Personas
Each request will also need either the personaId
or displayName
parameter, if specified.
If you're using the displayName variable be warned that for Xbox One and PlayStation 4 the api can only retrieve data if the player has played Battlefield 4 or Hardline.
Game
Certain requests can have an optional game parameter. The default value is tunguska
, which is the codename for Battlefield 1. It's possible to set this to bf4
to get data from Battlefield 4.
Platforms
This is just an enum to allow for more human readable code and is completely optional.
Platforms.XBOX
: 1
Platforms.PS4
: 2
Platforms.PC
: 3
Api.request
A generic request can be made to obtain anything from the api, however at this time all are covered with the rest of the apis.
const route = '/Stats/CareerForOwnedGames';
const params = { platform: bf.Platforms.XBOX, personaId: xxxxxxxxx };
bf.Api.request(route, params, console.log);
The route
argument may be any of the Request Routes
mentioned in this documentation.
Stats
Stats.careerForOwnedGames
Parameters: platform
, personaId
, displayName
Request Route: /Stats/CareerForOwnedGames
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YourOriginUserName,
}
bf.Stats.careerForOwnedGames(params, (error, response) => {
})
Stats.basicStats
Parameters: platform
, personaId
, displayName
, game
Request Route: /Stats/BasicStats
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YourOriginUserName,
game: 'tunguska'
}
bf.Stats.basicStats(params, (error, response) => {
})
Stats.detailedStats
Parameters: platform
, personaId
, displayName
, game
Request Route: /Stats/DetailedStats
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YourOriginUserName,
game: 'tunguska'
}
bf.Stats.detailedStats(params, (error, response) => {
})
Progression
Progression.getCodex
Parameters: platform
, game
Request Route: /Progression/GetCodex
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
game: 'tunguska'
}
bf.Progression.getCodex(params, (error, response) => {
})
Progression.getFilteredCodex
Parameters: platform
, personaId
, displayName
, game
Request Route: /Progression/GetFilteredCodex
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getFilteredCodex(params, (error, response) => {
})
Progression.getKitRanksMap
Parameters: platform
, personaId
, displayName
, game
Request Route: /Progression/GetKitRanksMap
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getKitRanksMap(params, (error, response) => {
})
Progression.getMedals
Parameters: platform
, personaId
, displayName
, game
Request Route: /Progression/GetMedals
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getMedals(params, (error, response) => {
})
Progression.getVehicle
Parameters: platform
, vehicleId
, personaId
, displayName
, game
Request Route: /Progression/GetVehicle
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
vehicleId: VEHICLE_ID,
displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getVehicle(params, (error, response) => {
})
Progression.getVehicles
Parameters: platform
, personaId
, displayName
, game
Request Route: /Progression/GetVehicles
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getVehicles(params, (error, response) => {
})
Progression.getWeapon
Parameters: platform
, weaponId
, personaId
, displayName
, game
Request Route: /Progression/GetWeapon
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
weaponId: WEAPON_ID,
displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getWeapon(params, (error, response) => {
})
Progression.getWeapons
Parameters: platform
, personaId
, displayName
, game
Request Route: /Progression/GetWeapons
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
displayName: YOUR_DISPLAY_NAME
}
bf.Progression.getWeapons(params, (error, response) => {
})
Loadout
Loadout.getItems
Parameters: platform
, game
Request Route: /Loadout/GetWeapons
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
}
bf.Loadout.getWeapons(params, (error, response) => {
})
Loadout.getItemGates
Parameters: platform
, game
Request Route: /Loadout/getItemGates
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PC,
}
bf.Loadout.getItemGates(params, (error, response) => {
})
Loadout.getPresets
Parameters: platform
, personaId
, displayName
, game
Request Route: /Loadout/GetPresets
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PS4,
displayName: YOUR_DISPLAY_NAME
}
bf.Loadout.getItemGates(params, (error, response) => {
})
Loadout.getEquippedDogtags
Parameters: platform
, personaId
, displayName
, game
Request Route: /Loadout/GetEquippedDogtags
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PS4,
displayName: YOUR_DISPLAY_NAME
}
bf.Loadout.getEquippedDogtags(params, (error, response) => {
})
Server
Server.quickServerInfo
Parameters: platform
, game
Request Route: /quick-server-info
Usage:
const bf = new require('battlefield-stats')(YOUR_API_KEY);
const params = {
platform: bf.Platforms.PS4,
game: 'tunguska'
}
bf.Server.quickServerInfo(params, (error, response) => {
})