API Integration
Integrate StatHarbour data into your applications, websites, or third-party services using our RESTful API.
Getting Started
Step 1: Generate an API Key
To access the API, you need to generate an API key from your league settings:
- Open your league, then Integration & API
- Choose the API Keys tab
- Click Generate New API Key
- Give your key a descriptive name (e.g., "Website Integration")
- Copy and save the generated key securely - it will only be shown once
Step 2: Copy the base URL from API Keys
Open Integration, then API Keys. The Base URL field is the prefix for every request. Copy it from that tab. Do not look through the browser's network log, and do not look up a project id.
The examples below write that prefix as https://YOUR_PROJECT_ID.supabase.co. Replace it with the host from the Base URL (the part before /functions/v1).
Step 3: Find Your League ID
Your league ID is required for all API requests. You can find it in:
- Your league's URL:
/league/{league-id}/... - The Documentation tab under Integration & API, which lists every endpoint with your league id already filled in
Authentication
All API requests require authentication using your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Rate Limits
API requests are limited per key, per hour:
- Default: 1000 requests per hour per API key
- The limit is adjustable per key in the API Keys tab
- Every response carries
X-RateLimit-Limit,X-RateLimit-RemainingandX-RateLimit-Reset(a Unix timestamp) - Exceeding the limit returns
429 Rate limit exceeded, not401, so a quota problem is never mistaken for a bad key
Available Endpoints
Query Parameters:
league_id(required) - Your league ID
Response: Array of teams with standings data including wins, losses, points, goal difference, etc.
Query Parameters:
league_id(required) - Your league IDstatus(optional) - Filter by game status:scheduled,in_progress,completedlimit(optional) - Number of games to return (default: 50)offset(optional) - Pagination offset (default: 0)
Response: Paginated list of games with team details, scores, dates, and status.
Query Parameters:
league_id(required) - Your league IDinclude_stats(optional) - Include team statistics:trueorfalseinclude_player_count(optional) - Include player count:trueorfalse
Response: Array of teams with optional statistics and player counts.
Query Parameters:
league_id(required) - Your league IDteam_id(optional) - Filter by specific team IDlimit(optional) - Number of players to return (default: 100)offset(optional) - Pagination offset (default: 0)
Response: Paginated list of players with team information and statistics.
Code Examples
JavaScript (fetch)
const SUPABASE_URL = 'https://YOUR_PROJECT_ID.supabase.co';
const API_KEY = 'your_api_key_here';
const LEAGUE_ID = 'your_league_id_here';
// Fetch league standings
async function getStandings() {
const response = await fetch(
`${SUPABASE_URL}/functions/v1/api-leagues-standings?league_id=${LEAGUE_ID}`,
{
headers: {
'Authorization': `Bearer ${API_KEY}`
}
}
);
const data = await response.json();
console.log('Standings:', data);
return data;
}
// Fetch upcoming games
async function getUpcomingGames() {
const response = await fetch(
`${SUPABASE_URL}/functions/v1/api-leagues-games?league_id=${LEAGUE_ID}&status=scheduled&limit=10`,
{
headers: {
'Authorization': `Bearer ${API_KEY}`
}
}
);
const data = await response.json();
console.log('Upcoming Games:', data);
return data;
}
// Fetch all teams with stats
async function getTeams() {
const response = await fetch(
`${SUPABASE_URL}/functions/v1/api-leagues-teams?league_id=${LEAGUE_ID}&include_stats=true`,
{
headers: {
'Authorization': `Bearer ${API_KEY}`
}
}
);
const data = await response.json();
console.log('Teams:', data);
return data;
}
// Use the functions
getStandings();
getUpcomingGames();
getTeams();
Python (requests)
import requests
SUPABASE_URL = 'https://YOUR_PROJECT_ID.supabase.co'
API_KEY = 'your_api_key_here'
LEAGUE_ID = 'your_league_id_here'
headers = {
'Authorization': f'Bearer {API_KEY}'
}
# Fetch league standings
def get_standings():
url = f'{SUPABASE_URL}/functions/v1/api-leagues-standings'
params = {'league_id': LEAGUE_ID}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print('Standings:', data)
return data
else:
print(f'Error: {response.status_code}')
return None
# Fetch completed games
def get_completed_games():
url = f'{SUPABASE_URL}/functions/v1/api-leagues-games'
params = {
'league_id': LEAGUE_ID,
'status': 'completed',
'limit': 20
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print('Completed Games:', data)
return data
else:
print(f'Error: {response.status_code}')
return None
# Fetch players from specific team
def get_team_players(team_id):
url = f'{SUPABASE_URL}/functions/v1/api-leagues-players'
params = {
'league_id': LEAGUE_ID,
'team_id': team_id
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print('Players:', data)
return data
else:
print(f'Error: {response.status_code}')
return None
# Use the functions
get_standings()
get_completed_games()
get_team_players('team-id-here')
cURL
# Get league standings
curl -X GET "https://YOUR_PROJECT_ID.supabase.co/functions/v1/api-leagues-standings?league_id=YOUR_LEAGUE_ID" \
-H "Authorization: Bearer YOUR_API_KEY"
# Get scheduled games
curl -X GET "https://YOUR_PROJECT_ID.supabase.co/functions/v1/api-leagues-games?league_id=YOUR_LEAGUE_ID&status=scheduled&limit=10" \
-H "Authorization: Bearer YOUR_API_KEY"
# Get teams with statistics
curl -X GET "https://YOUR_PROJECT_ID.supabase.co/functions/v1/api-leagues-teams?league_id=YOUR_LEAGUE_ID&include_stats=true" \
-H "Authorization: Bearer YOUR_API_KEY"
# Get all players
curl -X GET "https://YOUR_PROJECT_ID.supabase.co/functions/v1/api-leagues-players?league_id=YOUR_LEAGUE_ID&limit=50" \
-H "Authorization: Bearer YOUR_API_KEY"
Response Format
All successful API responses follow this general structure:
{
"league_id": "your-league-id",
"data": [...], // Array of items (teams, games, players, etc.)
"pagination": {
"total": 100,
"limit": 50,
"offset": 0
},
"last_updated": "2024-01-15T10:30:00Z"
}
Error Responses
Error responses include a message and appropriate HTTP status code:
{
"error": "Invalid API key",
"message": "The provided API key is invalid or expired"
}
Common HTTP Status Codes:
200- Success400- Bad Request (missing required parameters)401- Unauthorized (invalid or missing API key)403- Forbidden (API key doesn't have access to this league)404- Not Found (league or resource doesn't exist)429- Too Many Requests (rate limit exceeded)500- Internal Server Error
Use Cases
Public Website Integration
Display live standings, upcoming games, and team stats on your league's public website.
Mobile App Development
Build native mobile apps for iOS or Android that show real-time league data.
Data Analytics
Export data to business intelligence tools for advanced analytics and reporting.
Third-Party Integrations
Connect StatHarbour with other services like Discord bots, Slack notifications, or custom dashboards.
Best Practices
- Cache API responses when appropriate to reduce unnecessary requests
- Implement exponential backoff for retry logic on failed requests
- Monitor your API usage through the API Access dashboard
- Use the
limitandoffsetparameters for pagination on large datasets - Rotate API keys regularly for security
- Never expose API keys in client-side code or public repositories
- Use environment variables to store API credentials
- Set appropriate rate limits based on your actual usage needs
Need Help?
If you need assistance with API integration:
- Check the Widget Documentation for easier integration options
- Review code examples above for common use cases
- Contact support through the app if you encounter issues