Export every round to CSV
Walk every page of your rounds and write one CSV row per round, ready for a spreadsheet.
This script pages through GET /v1/rounds and writes rounds.csv with one row per round: date, course, tee, holes, strokes, par, and score to par.
Needs: a key with rounds:read, exported as NEW_JUNE_API_KEY.
#!/usr/bin/env bash
# export-rounds.sh: needs curl and jq.
set -euo pipefail
out="rounds.csv"
echo "id,started_at,timezone,status,play_mode,course,facility,tee,holes_scored,total_strokes,par_total,score_to_par" > "$out"
cursor=""
while :; do
url="https://data.newjune.co/v1/rounds?limit=100"
if [ -n "$cursor" ]; then url="$url&cursor=$cursor"; fi
page=$(curl -sf "$url" -H "Authorization: Bearer $NEW_JUNE_API_KEY")
echo "$page" | jq -r '.data[] | [
.id, .started_at, .timezone, .status, .play_mode,
.course.name, .course.facility_name, .tee.name,
.holes_scored, .total_strokes, .par_total, .score_to_par
] | @csv' >> "$out"
if [ "$(echo "$page" | jq -r '.has_more')" != "true" ]; then break; fi
cursor=$(echo "$page" | jq -r '.next_cursor')
done
echo "Wrote $(($(wc -l < "$out") - 1)) rounds to $out"// export-rounds.mts: Node 20+, no dependencies. Run with: npx tsx export-rounds.mts
import { writeFileSync } from 'node:fs';
interface Round {
id: string;
started_at: string;
timezone: string | null;
status: string;
play_mode: string;
course: { name: string; facility_name: string } | null;
tee: { name: string } | null;
holes_scored: number;
total_strokes: number | null;
par_total: number | null;
score_to_par: number | null;
}
async function* listAll<T>(path: string, params: Record<string, string> = {}) {
let cursor: string | null = null;
do {
const url = new URL(`https://data.newjune.co/v1/${path}`);
url.searchParams.set('limit', '100');
for (const [name, value] of Object.entries(params)) url.searchParams.set(name, value);
if (cursor) url.searchParams.set('cursor', cursor);
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.NEW_JUNE_API_KEY}` },
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
const page = (await response.json()) as { data: T[]; has_more: boolean; next_cursor: string | null };
yield* page.data;
cursor = page.has_more ? page.next_cursor : null;
} while (cursor);
}
function csvCell(value: string | number | null | undefined): string {
if (value === null || value === undefined) return '';
const text = String(value);
return /[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
}
const header = [
'id', 'started_at', 'timezone', 'status', 'play_mode', 'course', 'facility', 'tee',
'holes_scored', 'total_strokes', 'par_total', 'score_to_par',
];
const rows = [header.join(',')];
for await (const round of listAll<Round>('rounds')) {
rows.push(
[
round.id, round.started_at, round.timezone, round.status, round.play_mode,
round.course?.name, round.course?.facility_name, round.tee?.name,
round.holes_scored, round.total_strokes, round.par_total, round.score_to_par,
].map(csvCell).join(',')
);
}
writeFileSync('rounds.csv', `${rows.join('\n')}\n`);
console.log(`Wrote ${rows.length - 1} rounds to rounds.csv`);# export_rounds.py: needs requests (pip install requests).
import csv
import os
import requests
API = "https://data.newjune.co/v1"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['NEW_JUNE_API_KEY']}"
def list_all(path, **params):
params = {"limit": 100, **params}
while True:
response = session.get(f"{API}/{path}", params=params, timeout=30)
response.raise_for_status()
page = response.json()
yield from page["data"]
if not page["has_more"]:
return
params["cursor"] = page["next_cursor"]
fields = [
"id", "started_at", "timezone", "status", "play_mode", "course", "facility", "tee",
"holes_scored", "total_strokes", "par_total", "score_to_par",
]
count = 0
with open("rounds.csv", "w", newline="") as file:
writer = csv.DictWriter(file, fieldnames=fields)
writer.writeheader()
for round_ in list_all("rounds"):
course = round_["course"] or {}
tee = round_["tee"] or {}
writer.writerow({
"id": round_["id"],
"started_at": round_["started_at"],
"timezone": round_["timezone"],
"status": round_["status"],
"play_mode": round_["play_mode"],
"course": course.get("name"),
"facility": course.get("facility_name"),
"tee": tee.get("name"),
"holes_scored": round_["holes_scored"],
"total_strokes": round_["total_strokes"],
"par_total": round_["par_total"],
"score_to_par": round_["score_to_par"],
})
count += 1
print(f"Wrote {count} rounds to rounds.csv")Notes
- Only finished rounds: add
status=completedto the request (listAll('rounds', { status: 'completed' }),list_all("rounds", status="completed"), or&status=completedin the URL). - A date range: add
started_afterandstarted_before, for examplestarted_after=2026-01-01T00:00:00Z. - Empty cells are
nullvalues: a round with no course data, or no holes scored yet. - Hole by hole: for each round, list
GET /v1/hole_scores?round_id=<id>and write one row per hole. That is one extra request per round, so see Rate limits before exporting years of rounds.