What you will build
A command-line script. Give it a date and it prints every NBA game of that night, in the same order as the schedule:
Cleveland Cavaliers 119 – 124 Miami Heat (Ended)
Q1 Q2 Q3 Q4
CLE 29 29 20 41
MIA 36 20 32 36
CLE MIN PTS REB AST STL BLK TO FG 3PT FT +/-
D. Mitchell 35:13 27 4 9 5 0 6 9-21 2-5 7-9 -3
J. Allen 32:46 21 11 2 3 1 2 8-10 0-0 5-6 -6
J. Harden 34:24 20 4 9 0 0 2 6-15 2-6 6-7 -11
M. Thomas 24:15 18 1 2 1 0 1 7-10 3-4 1-1 5
…
Out: E. Mobley (injury), N. Tomlin (injury)
MIA MIN PTS REB AST STL BLK TO FG 3PT FT +/-
G. Antetokounmpo 32:23 36 9 4 2 1 4 13-23 0-0 10-11 18
B. Adebayo 38:29 19 9 3 2 0 4 6-13 2-4 5-6 -2
…Two endpoints do all the work: GET /v2/fixtures lists the games of a day and GET /v2/fixtures/{id}/lineups returns both rosters with each player's figures for the game. Everything else is formatting. The NBA API page lists what else the league carries: standings, playoff series, the draft and shot charts.
1. Get a key and read one night
Create a free account on the sign-up page and copy the key the welcome page shows you; it starts with sk_live_. Keep it in an environment variable, not in the code:
export DATASPORTSAPI_API_KEY="sk_live_…"The NBA is league 198277. NBA nights are US nights, so ask for the day in New York time with tz: a 7:30 pm tip-off is already the next day in UTC, and without tz it would land on the wrong date.
curl -H "Authorization: Bearer $DATASPORTSAPI_API_KEY" \
"https://api.datasportsapi.com/v2/fixtures?league=198277&date=2026-11-29&tz=America/New_York"One game of the answer, trimmed to the fields the script reads:
{
"data": [
{
"id": 198268,
"status": { "type": "finished", "description": "Ended" },
"startTime": "2026-11-29T20:30:00.000Z",
"home": { "name": "Cleveland Cavaliers", "shortName": "Cavaliers", "code": "CLE" },
"away": { "name": "Miami Heat", "shortName": "Heat", "code": "MIA" },
"homeScore": { "current": 119, "periods": { "period1": 29, "period2": 29, "period3": 20, "period4": 41 } },
"awayScore": { "current": 124, "periods": { … } }
}
],
"meta": { "date": "2026-11-29", "tz": "America/New_York", "count": 10 }
}status.type is notstarted, inprogress or finished, and status.description says the same in words. homeScore.periods holds the points of each quarter, and overtime gets its own key when a game needs one.
2. Ask politely: a fetch helper
On a busy night the script makes more than ten calls, which is more than the Free plan's per-minute allowance. When that happens the API answers 429 with a Retry-After header; the helper waits that many seconds and asks again. Every other error is reported with the API's own code, for example history_not_in_plan for a date older than your plan reaches:
// boxscore.mjs: run with node boxscore.mjs 2026-11-29
const KEY = process.env.DATASPORTSAPI_API_KEY;
const API = "https://api.datasportsapi.com";
const NBA = 198277;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
async function api(path) {
for (;;) {
const res = await fetch(API + path, { headers: { Authorization: `Bearer ${KEY}` } });
if (res.status === 429) {
const body = await res.json();
if (body.error?.code === "quota_exceeded") throw new Error("The day's requests are used up.");
const wait = Number(res.headers.get("retry-after")) || 10;
console.error(`(rate limit: waiting ${wait} s)`);
await sleep(wait * 1000);
continue;
}
const body = await res.json();
if (!res.ok) throw new Error(`${body.error?.code}: ${body.error?.message}`);
return body;
}
}Node.js 18 or later has fetch built in, so the file needs no packages. If you prefer a client library, the datasportsapi package on npm has the same two calls as client.fixtures.list(…) and client.fixtures.lineups(id) and retries rate limits for you.
3. The score by quarter
The line score comes straight from the schedule: no extra call. Quarters are period1 to period4; anything after them is overtime:
// Add to boxscore.mjs.
const pad = (s, n) => String(s).padStart(n);
const label = (key) => (key.startsWith("period") ? "Q" + key.slice(6) : "OT");
function lineScore(game) {
const keys = Object.keys(game.homeScore.periods ?? {});
console.log(" " + keys.map((k) => pad(label(k), 4)).join(""));
for (const side of ["home", "away"]) {
const periods = game[side + "Score"].periods ?? {};
console.log(" " + (game[side].code ?? "").padEnd(6) + keys.map((k) => pad(periods[k] ?? "-", 4)).join(""));
}
}4. The box score
GET /v2/fixtures/{id}/lineups returns each side's players, every one with a statistics object for the game. The keys are the usual box score: secondsPlayed, points, rebounds (split into offensiveRebounds and defensiveRebounds), assists, steals, blocks, turnovers, personalFouls, plusMinus, and made and attempted counts for field goals, threes and free throws. missing lists the players who sat out and why:
// Add to boxscore.mjs.
const minutes = (s) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
const made = (st, what) => `${st[what + "Made"] ?? 0}-${st[what + "Attempted"] ?? 0}`;
function boxScore(code, side) {
console.log(`\n ${code.padEnd(16)} MIN PTS REB AST STL BLK TO FG 3PT FT +/-`);
const played = side.players.filter((p) => p.statistics);
played.sort((a, b) => b.statistics.points - a.statistics.points);
for (const p of played) {
const st = p.statistics;
console.log(
" " + (p.player.shortName ?? p.player.name).padEnd(16) +
pad(minutes(st.secondsPlayed ?? 0), 7) +
[st.points, st.rebounds, st.assists, st.steals, st.blocks, st.turnovers].map((n) => pad(n ?? 0, 5)).join("") +
pad(made(st, "fieldGoals"), 7) + pad(made(st, "threePointers"), 7) + pad(made(st, "freeThrows"), 7) +
pad(st.plusMinus ?? "", 6),
);
}
if (side.missing?.length) {
console.log(" Out: " + side.missing.map((m) => `${m.player.shortName ?? m.player.name} (${m.reason ?? m.availability})`).join(", "));
}
}A player who did not get on the court has statistics: null, which is why the filter comes first. Sorting by points puts the night's top scorer on top; sort by secondsPlayed instead for a classic starters-first look, or keep the API's order and read substitute to split starters from the bench.
5. Put it together
// Add to the end of boxscore.mjs.
const date = process.argv[2] ?? new Date(Date.now() - 86400e3).toISOString().slice(0, 10);
const day = await api(`/v2/fixtures?league=${NBA}&date=${date}&tz=America/New_York`);
if (!day.data.length) console.log(`No NBA games on ${date}.`);
for (const game of day.data) {
const { home, away, status } = game;
console.log(`\n${home.name} ${game.homeScore.current ?? "-"} – ${game.awayScore.current ?? "-"} ${away.name} (${status.description})`);
if (status.type === "notstarted") continue; // no box score before tip-off
lineScore(game);
const { data } = await api(`/v2/fixtures/${game.id}/lineups`);
boxScore(home.code, data.home);
boxScore(away.code, data.away);
}node boxscore.mjs 2026-11-29
# no date: yesterday's gamesRun it during a game and the figures are the live ones: the line-ups are read again about every 10 seconds while a game is followed, so a second run a minute later shows the new totals. To follow one game, call it in a loop every 30 to 60 seconds; on the Free plan keep an eye on the daily allowance.
Where to go next
- Save the rows to a CSV file instead of printing them, and you have a game log for a fantasy or betting model.
- Add the standings under each night with
/v2/leagues/198277/standings. - Every shot of a game on the court, made or missed, is
/v2/fixtures/{id}/shotmap(Pro). - A web page instead of a terminal: the live score app guide shows the server and page around the same kind of call.