GetPlayerAchievements

What is an API? API stands for Application program interface and it is a set of routines, protocols, and tools for building software applications.


Getting Strated With Express


Enter the following in 'server.js'

var key = 'steamKey';
var steamID = 'steamID';
var express = require('express');
var app = express();
var handlebars = require('express-handlebars').create({
defaultLayout: 'main'
});
var request = require('request');
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('port', 3000); app.listen(app.get('port'), function(){
console.log('Express started on http://localhost:' + app.get('port') + '; press Ctrl-C to terminate.');
});
  1. var key = 'steamKey';
    Store your steam Key in a variable
  2. var steamID = 'steamID';
    Store your steam ID in a variable
  3. var express = require('express');
    var app = express();

    Creates an Express application.
  4. var handlebars = require('express-handlebars').create({
    defaultLayout: 'main'
    });
    app.engine('handlebars', handlebars.engine);

    This is so that you can use Handlebars
  5. var request = require('request');
    This is so that you can use 'request' in your app.
  6. app.set('view engine', 'handlebars');
    Set which view engine to use.
  7. app.set('port', 3000);
    Set the port
  8. app.listen(app.get('port'), function()
    Make Sure the app is running with a console command.

Using The GetPlayerAchievements Method


  1. var url='http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=22380&key='+key+'&steamid='+steamID;
    This is the formatted url we are using to retrieve the data in JSON form.
  2. request.get(url, function(error, sResponse, sBody) {
    Store your steam ID in a variable
  3. var express = require('express');
    var app = express();

    Creates an Express application.

Enter the following in 'server.js'

app.get('/', function(httpRequest, httpResponse) {
var url='http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=22380&key='+key+'&steamid='+steamID;
request.get(url, function(error, sResponse, sBody) {
httpResponse.render('home', {sBody}); });
});

End Result


Notice that the returned results is in JSON format. This is because by default the Steam API returns JSON objects.

GetPlayerAchievements

Important


This guide will help you get started with the Steam API but first it’s important to understand how to use the Steam API.

Every method in the Steam API can return its results in 3 different formats: JSON, XML, and VDF. Each format represents the data described herein differently. For the purpose of this tutorial we will be focusing on working with JSON.


The Basic API call


In order to use the API using GET or POST the URI format of each API request has to begin like so:

http://api.steampowered.com/

This is a template for how the url is to be formatted to return data in JSON format::

http://api.steampowered.com/"interface"/"method"/"method_version"/

Interface:


You can view all of them here:

Steam Interfaces

This is a template for how the url is to be formatted to return data in JSON format::

http://api.steampowered.com/"interface"/"method"/"method_version"/

Here’s a look at the iSteamUserStats:

{ "name": "ISteamUserStats", "methods": [ { "name": "GetGlobalAchievementPercentagesForApp", "version": 1, "httpmethod": "GET", "parameters": [ { "name": "gameid", "type": "uint64", "optional": false, "description": "GameID to retrieve the achievement percentages for" } ] }, { "name": "GetGlobalAchievementPercentagesForApp", "version": 2, "httpmethod": "GET", "parameters": [ { "name": "gameid", "type": "uint64", "optional": false, "description": "GameID to retrieve the achievement percentages for" } ] }, { "name": "GetGlobalStatsForGame", "version": 1, "httpmethod": "GET", "parameters": [ { "name": "appid", "type": "uint32", "optional": false, "description": "AppID that we're getting global stats for" }, { "name": "count", "type": "uint32", "optional": false, "description": "Number of stats get data for" }, { "name": "name[0]", "type": "string", "optional": false, "description": "Names of stat to get data for" }, { "name": "startdate", "type": "uint32", "optional": true, "description": "Start date for daily totals (unix epoch timestamp)" }, { "name": "enddate", "type": "uint32", "optional": true, "description": "End date for daily totals (unix epoch timestamp)" } ] },

We Will be using this When We Call it and display it with Handlebars:


64x64

HOME

The Steam Api doesn’t allow for cross-origin so first we will have to create our own server using Node!

Setup Node Server

The Steam Api doesn’t allow for cross-origin so first we will have to create our own server using Node!

API Setup

Set up the Steam API!

GetPlayerAchievements

Use The API for the first time.

JSON and HandleBars

Learn how to Use JSON and Handlebars together.

Examples

A few Example Calls to get you familiar with the API.