STAT-API
PGA Cookbook

Read a PGA golfer's leaderboard finishes

The leaderboards table has one row per player per tournament: rank, total score, earnings, and strokes-gained splits. Pick a golfer and read their finishes.

1.Pick a golfer

A one-row page gives us a valid player id to filter finishes by.

const players = (await api.pga.players.list({ limit: 1 })).players

The complete program

Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.

import { StatApi } from '@stat-api/client'

const api = new StatApi() // reads STAT_API_KEY from the environment

// Pick a golfer
const players = (await api.pga.players.list({ limit: 1 })).players

// Read that golfer's finishes
const board = (await api.pga.leaderboards.list({ player_id: players[0].id, limit: 25 })).leaderboards

// Best finishes first
const ranked = [...board].sort((a, b) => (a.rank ?? 0) - (b.rank ?? 0))

// Show the finishes
console.log(["rank", "sg_total"].join('\t'))
for (const row of ranked) {
  console.log([String(row.rank ?? ''), String(row.sg_total ?? '')].join('\t'))
}