ShotTracker Developer

Unparalleled data set + realtime API = future of sports. Build with live tracking, stats, and broadcast-ready endpoints.

Event API

Event API — Code examples

Authentication, WebSocket, and payload examples for the Event API. For authentication details see the Event API overview; for field definitions see the Data and Field Reference.

REST request signing (Node.js)

Example (javascript)
var crypto = require("crypto");

var userName = process.env.EVENT_USERNAME || "your-username";
var secret = process.env.EVENT_SECRET || "your-secret";
var host = "api.shottracker.com";
var pathUriWithoutQueryString = "/v1/data/teams/123/events";
var method = "GET";
var date = new Date().toUTCString();

var requestLine = method + " " + pathUriWithoutQueryString + " HTTP/1.1";
var stringToSign =
  "date: " + date.trim() + "
" +
  "host: " + host + "
" +
  requestLine;
var encodedSignature = crypto
  .createHmac("sha1", secret)
  .update(stringToSign)
  .digest("base64");
var hmacAuth =
  'hmac username="' + userName +
  '",algorithm="hmac-sha1",headers="date host request-line",signature="' +
  encodedSignature + '"';

// Send with your request: date, host, Authorization: <hmacAuth>

REST request signing (Python)

Example (python)
import hmac
import base64
import os
from datetime import datetime, timezone

username = os.environ.get("EVENT_USERNAME")
secret = os.environ.get("EVENT_SECRET").encode("utf-8")
host = "api.shottracker.com"
path_only = "/v1/data/teams/123/events"  # no query string
method = "GET"
date = datetime.now(timezone.utc).strftime("%a, %d %b %Y %H:%M:%S GMT")
request_line = f"{method} {path_only} HTTP/1.1"
string_to_sign = f"date: {date}\nhost: {host}\n{request_line}"
signature = base64.b64encode(
  hmac.new(secret, string_to_sign.encode("utf-8"), "sha1").digest()
).decode("ascii")
authorization = f'hmac username="{username}",algorithm="hmac-sha1",headers="date host request-line",signature="{signature}"'
# Send headers: date, host, Authorization

WebSocket (Live Data V2)

Example (javascript)
// 1. Get a subscription token from the REST API (HMAC-signed request):
//    GET /v1/data/schedule/games/{event_id}/_subscribe

// 2. Connect with the token in the query string:
var token = "6141681d-df46-11e6-a818-f20e96351dc1";
var ws = new WebSocket(
  "wss://api.shottracker.com/live/v2/games?token=" +
  encodeURIComponent(token)
);

WebSocket connection URL

Example (text)
wss://api.shottracker.com/live/v2/games?token=[subscription token]&source=[source]&broadcast_summary_level=[level]&last_seq=[sequence]

Development: wss://devapi.shottracker.com/live/v2/games

WebSocket keep-alive (ping / pong)

Example (json)
Client → Server:
{
  "action": "ping"
}

Server → Client:
{
  "action": "pong"
}

WebSocket message shape examples

Example (json)
Data message (with sequence):
{"seq":"25","type":"data","source":"boxscorestatsv2","data":{...}}

Data message (no sequence):
{"type":"data","source":"location","data":{...}}

Ping (client → server):
{"action":"ping"}

Pong (server → client):
{"action":"pong"}

Example payload: stats (WebSocket)

Example (json)
{
  "type": "stats",
  "data": {
    "occurred_at": 1500571319432,
    "team_id": 461,
    "player_id": 2623,
    "stats": {
      "FGA": 15,
      "FG": 8,
      "PTS": 17
    },
    "classification": "TWO_POINT_MAKE",
    "version": 1941
  }
}

Example payload: shot (WebSocket)

Example (json)
{
  "type": "shot",
  "data": {
    "occurred_at": 1500571319432,
    "team_id": 461,
    "player_id": 2623,
    "is_make": true,
    "is_3point": false,
    "zone": 1,
    "hoop_player_x": 685,
    "hoop_player_y": -475,
    "status": "RECORDED"
  }
}

Example payload: location (WebSocket)

Example (json)
{
  "type": "location",
  "data": {
    "occurred_at": 1500571321532,
    "type": "PLAYER",
    "id": 2942,
    "x": 2314,
    "y": -8635,
    "z": 69,
    "speed": 0.1,
    "dist": 1.3
  }
}