API Integration

Integrate StatHarbour data into your applications, websites, or third-party services using our RESTful API.

Pro and Elite: The read API is included on Pro and Elite. View pricing plans

Getting Started

Step 1: Generate an API Key

To access the API, you need to generate an API key from your league settings:

  1. Open your league, then Integration & API
  2. Choose the API Keys tab
  3. Click Generate New API Key
  4. Give your key a descriptive name (e.g., "Website Integration")
  5. Copy and save the generated key securely - it will only be shown once
Important: Store your API key securely. It will only be displayed once during generation. If you lose it, you'll need to generate a new one.

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:

Available Endpoints

GET
/functions/v1/api-leagues-standings
Retrieve league standings with team statistics

Query Parameters:

Response: Array of teams with standings data including wins, losses, points, goal difference, etc.

GET
/functions/v1/api-leagues-games
Get all games for your league

Query Parameters:

Response: Paginated list of games with team details, scores, dates, and status.

GET
/functions/v1/api-leagues-teams
Get all teams in your league

Query Parameters:

Response: Array of teams with optional statistics and player counts.

GET
/functions/v1/api-leagues-players
Retrieve all players in your league

Query Parameters:

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:

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

Need Help?

If you need assistance with API integration: