Code Examples
Ready-to-use code snippets in multiple languages.
List Courses
curl
# List courses in California
curl "https://golfly.dev/api/v1/courses?state=California&limit=10" \
-H "x-api-key: gf_your_api_key"
# Search courses by name
curl "https://golfly.dev/api/v1/courses?search=pebble&limit=5" \
-H "x-api-key: gf_your_api_key"
# Filter by minimum rating
curl "https://golfly.dev/api/v1/courses?min_rating=4.5&limit=10" \
-H "x-api-key: gf_your_api_key"Get Course Details
curl
# Get course by ID
curl "https://golfly.dev/api/v1/courses/7072" \
-H "x-api-key: gf_your_api_key"Fetch All Courses
javascript
async function getAllCourses(state) {
const courses = [];
let offset = 0;
while (true) {
// API returns max_limit based on your plan
const { data, meta } = await getCourses({ state, offset });
courses.push(...data);
if (!meta.has_more) break;
offset += meta.limit;
// Respect rate limits
await new Promise(r => setTimeout(r, 100));
}
return courses;
}
// Usage
const allCaliforniaCourses = await getAllCourses('California');
console.log(`Fetched ${allCaliforniaCourses.length} courses`);GPS Hole Data (Pro)
Requires Pro or Enterprise plan
curl
# Get hole GPS coordinates
curl "https://golfly.dev/api/v1/courses/19271/holes" \
-H "x-api-key: gf_your_api_key"Type Definitions
typescript
interface Course {
course_id: number;
name: string;
address: string;
city: string;
state: string;
latitude: number;
longitude: number;
rating: string | null;
num_reviews: number;
holes: number;
par: string;
length_yards: number;
slope?: string;
year_built?: number;
architects?: string;
tee_data?: TeeBox[];
}
interface TeeBox {
name: string;
par: string;
length: string;
slope: string;
}
interface CoursesResponse {
data: Course[];
meta: {
total: number;
limit: number;
max_limit: number;
offset: number;
has_more: boolean;
};
}
interface Hole {
hole_number: number;
par: number;
length_yards: number;
coordinates: {
tee: Coordinate;
green: {
front: Coordinate;
center: Coordinate;
back: Coordinate;
};
fairway?: Coordinate;
dogleg?: Coordinate;
layup?: Coordinate;
};
hazards: Hazard[];
}
interface Coordinate {
lat: number;
lng: number;
}
interface Hazard {
type: 'bunker' | 'water';
label: string;
lat: number;
lng: number;
}