API Documentation

Welcome to the Realtime Sports API documentation. This API provides real-time access to NFL and College Football data including events, plays, penalties, teams, officials, and athletes.

Base URL

https://realtimesportsapi.com

Authentication

All API requests require authentication using JWT tokens. Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Note: Get your API key from the dashboard.

Rate Limits

Rate limits vary by subscription tier. All limits reset daily at midnight EST.

TierCalls/MonthCalls/Second
Free1251
Starter10,0005
Pro50,00020
EnterpriseUnlimited100+

API Structure

The API follows a hierarchical structure: Sport → League → Resource

/api/v1/sports
  /{sport}/leagues
    /{league}
      /teams                    # All teams in league
      /athletes                 # All athletes (paginated)
        /{athleteId}            # Single athlete
      /seasons                  # Historical seasons
        /{year}                 # Season details
      /events                   # All events
        /live                   # Live events only
        /{eventId}              # Single event
          /plays                # Play-by-play (paginated)
          /penalties            # Penalties only

Sports & Leagues

GET/v1/sports

Get all available sports.

Example Request

curl -X GET "https://realtimesportsapi.com/api/v1/sports" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

{
  "success": true,
  "data": [
    {
      "id": "20",
      "name": "Football",
      "slug": "football",
      "displayName": "Football"
    },
    {
      "id": "40",
      "name": "Basketball",
      "slug": "basketball",
      "displayName": "Basketball"
    }
  ]
}
GET/v1/sports/:sport/leagues

Get all leagues for a specific sport.

Example Request

curl -X GET "https://realtimesportsapi.com/api/v1/sports/football/leagues" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

{
  "success": true,
  "data": [
    {
      "id": "28",
      "name": "National Football League",
      "slug": "nfl",
      "abbreviation": "NFL",
      "currentSeason": 2025
    },
    {
      "id": "35",
      "name": "NCAA Football",
      "slug": "college-football",
      "abbreviation": "NCAA"
    }
  ]
}

Teams

GET/sports/{sport}/leagues/{league}/teams

Get all teams for a league.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/baseball/leagues/mlb/teams" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response Includes

  • ✓ Team names, abbreviations, slugs
  • ✓ Logos (default & dark theme, proxied)
  • ✓ Team colors (hex codes)
  • ✓ Venue information (stadium, capacity)
  • ✓ Records and standings

Athletes

GET/sports/{sport}/leagues/{league}/athletes

Get all athletes for a league (paginated).

Note: MLB has 36,000+ athletes. Always use pagination!

Query Parameters

  • page - Page number (default: 1)
  • limit - Results per page (default: 25)

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/baseball/leagues/mlb/athletes?page=1&limit=25" \
  -H "Authorization: Bearer YOUR_API_KEY"
GET/sports/{sport}/leagues/{league}/athletes/{athleteId}

Get single athlete by ID.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/baseball/leagues/mlb/athletes/30836" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response Includes

  • ✓ Full name, position, jersey number
  • ✓ Headshot (proxied image)
  • ✓ Team affiliation
  • ✓ Age and stats availability

Seasons

GET/sports/{sport}/leagues/{league}/seasons

Get all seasons for a league (historical data).

Note: MLB has 150+ seasons dating back to 1870s!

Query Parameters

  • page - Page number (default: 1)
  • limit - Results per page (default: 25)

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/seasons?limit=5" \
  -H "Authorization: Bearer YOUR_API_KEY"
GET/sports/{sport}/leagues/{league}/seasons/{year}

Get details for a specific season.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/baseball/leagues/mlb/seasons/2025" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response Includes

  • ✓ Season year and display name
  • ✓ Current season type (preseason, regular, postseason, offseason)
  • ✓ Start and end dates
  • ✓ All season types with dates

Events

GET/sports/{sport}/leagues/{league}/events

Get all events for a league.

Query Parameters

  • limit - Results per page (default: 50)

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events?limit=10" \
  -H "Authorization: Bearer YOUR_API_KEY"
GET/sports/{sport}/leagues/{league}/events/live

Get currently live events only.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events/live" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

{
  "success": true,
  "data": [
    {
      "id": "401772982",
      "name": "Buffalo Bills at Denver Broncos",
      "shortName": "BUF @ DEN",
      "date": "2026-01-17T21:30Z",
      "status": {
        "state": "in",
        "period": 3,
        "clock": "10:45"
      },
      "homeTeam": {
        "id": "7",
        "name": "Denver Broncos",
        "abbreviation": "DEN",
        "logo": "/api/images/proxy?url=...",
        "color": "0a2343",
        "score": 21
      },
      "awayTeam": {
        "id": "2",
        "name": "Buffalo Bills",
        "abbreviation": "BUF",
        "score": 17
      },
      "venue": {
        "name": "Empower Field at Mile High",
        "city": "Denver",
        "state": "CO"
      }
    }
  ]
}
GET/sports/{sport}/leagues/{league}/events/{eventId}

Get single event with full details.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events/401772982" \
  -H "Authorization: Bearer YOUR_API_KEY"

Plays & Pagination

GET/sports/{sport}/leagues/{league}/events/{eventId}/plays

Get plays for an event (paginated - games can have 200+ plays).

Query Parameters

  • page - Page number (default: 1)
  • limit - Plays per page (default: 25, max: 100)

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events/401772982/plays?page=1&limit=25" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

{
  "success": true,
  "data": [
    {
      "id": "40177298265",
      "text": "B.Nix pass to P.Bryant for 12 yards",
      "type": { "id": "24", "text": "Pass Reception" },
      "period": 1,
      "clock": { "displayValue": "14:56" },
      "situation": {
        "down": 1,
        "distance": 10,
        "yardLine": 26,
        "downDistanceText": "1st & 10 at DEN 26"
      },
      "yardsGained": 12,
      "athletes": [
        { "type": "passer", "order": 1 },
        { "type": "receiver", "order": 2 }
      ]
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "pageSize": 25,
      "total": 213,
      "totalPages": 9,
      "hasNextPage": true
    }
  }
}
GET/sports/{sport}/leagues/{league}/events/{eventId}/penalties

Get penalties only from an event.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events/401772982/penalties" \
  -H "Authorization: Bearer YOUR_API_KEY"

Betting & Odds

Get current odds (spread, moneyline, over/under), odds history for line movement, and real-time odds updates via webhooks and WebSockets. Ideal for betting apps, sportsbooks, and sharp tools.

GET/sports/{sport}/leagues/{league}/events/{eventId}/odds

Current betting odds for an event: spread, moneyline, and over/under. Same shape used when you request includeOdds=true on event or list endpoints.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events/401772982/odds" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

{
  "success": true,
  "data": {
    "spread": { "line": -3.5, "home": -110, "away": -110 },
    "moneyline": { "home": -180, "away": 150 },
    "overUnder": { "total": 48.5, "over": -110, "under": -110 },
    "provider": "ESPN",
    "updatedAt": "2026-01-28T20:00:00Z"
  }
}

Odds on event and list endpoints

Avoid N+1 calls by requesting odds with events in one go. Add includeOdds=true to:

  • Single event: GET .../events/{eventId}?includeOdds=true
  • Live events: GET .../events/live?includeOdds=true
  • League events: GET .../events?includeOdds=true
  • Season schedule: GET .../seasons/{season}/schedule?includeOdds=true (optional with week)

Each event in the response will include an odds property when available. Using includeOdds=true may increase latency and usage.

GET/sports/{sport}/leagues/{league}/events/{eventId}/odds/history

Historical odds for line movement, closing line, or movement alerts. Use limit (default 100) to control how many history entries are returned.

curl "https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events/401772982/odds/history?limit=50" \
  -H "Authorization: Bearer YOUR_API_KEY"

Real-time odds updates

When lines move, get notified without polling:

  • Webhook: Subscribe to event.odds_change. Your endpoint receives a POST when odds for that event change.
  • WebSocket: Listen for event_odds_change (Pro/Enterprise). Payload includes event id and updated odds.

Configure webhooks in your dashboard. See the Webhooks and WebSockets sections below for subscription details.

Example: Fetch live games with odds

// Live NFL games with current odds (one request)
const res = await fetch(
  'https://realtimesportsapi.com/api/v1/sports/football/leagues/nfl/events/live?includeOdds=true',
  { headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const { data: games } = await res.json();
games.forEach(g => {
  console.log(g.name, g.odds?.spread?.line, g.odds?.overUnder?.total);
});

JavaScript Example

const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://realtimesportsapi.com/api/v1';

// Discover sports and leagues
async function discoverAPI() {
  // Get all sports
  const sports = await fetch(`${BASE_URL}/sports`, {
    headers: { 'Authorization': `Bearer ${API_KEY}` }
  }).then(r => r.json());
  
  console.log('Sports:', sports.data);
  
  // Get football leagues
  const leagues = await fetch(`${BASE_URL}/sports/football/leagues`, {
    headers: { 'Authorization': `Bearer ${API_KEY}` }
  }).then(r => r.json());
  
  console.log('Leagues:', leagues.data);
}

// Get live NFL games
async function getLiveNFLGames() {
  const response = await fetch(
    `${BASE_URL}/sports/football/leagues/nfl/events/live`,
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  );
  
  const data = await response.json();
  
  if (data.success) {
    console.log('Live games:', data.data);
  }
}

// Get plays with pagination
async function getPlays(eventId, page = 1) {
  const response = await fetch(
    `${BASE_URL}/sports/football/leagues/nfl/events/${eventId}/plays?page=${page}&limit=25`,
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  );
  
  const data = await response.json();
  
  console.log(`Page ${page}: ${data.data.length} plays`);
  console.log(`Total: ${data.meta.pagination.total} plays`);
  
  return data;
}

// Get all plays (all pages)
async function getAllPlays(eventId) {
  const allPlays = [];
  let page = 1;
  let hasMore = true;
  
  while (hasMore) {
    const response = await getPlays(eventId, page);
    allPlays.push(...response.data);
    hasMore = response.meta.pagination.hasNextPage;
    page++;
  }
  
  return allPlays;
}

// Usage
discoverAPI();
getLiveNFLGames();
getAllPlays('401772982').then(plays => {
  console.log(`Fetched ${plays.length} total plays`);
});

Teams & Athletes

GET/sports/{sport}/leagues/{league}/teams

Get all teams for a league.

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/baseball/leagues/mlb/teams" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response Includes

  • ✓ Team names, abbreviations, colors
  • ✓ Logos (proxied through our CDN)
  • ✓ Venue information
  • ✓ Records and standings
GET/sports/{sport}/leagues/{league}/athletes

Get athletes (paginated - MLB has 36,000+!).

Example Request

curl "https://realtimesportsapi.com/api/v1/sports/baseball/leagues/mlb/athletes?page=1&limit=25" \
  -H "Authorization: Bearer YOUR_API_KEY"

Special Features

Image Proxying

All images (team logos, athlete headshots) are automatically proxied through our CDN.

// Team logos are proxied
"logo": "https://realtimesportsapi.com/api/images/proxy?url=..."

// Direct image access (no auth required)
<img src="/api/images/proxy?url=..." alt="Team Logo" />

Pagination Best Practices

  • ✓ Plays: Default 25 per page (games have 200+ plays)
  • ✓ Athletes: Default 25 per page (MLB: 36,000+)
  • ✓ Check hasNextPage in meta
  • ✓ Use totalPages to show progress

Rate Limit Headers

Check these headers in every response:

X-RateLimit-Limit: 50000
X-RateLimit-Remaining: 49995
X-RateLimit-Reset: 1642636800000  // Unix timestamp

WebSocket Support (Pro/Enterprise)

Stream real-time sports data directly to your application. Connect once, then subscribe to the event types you care about and optionally filter by sport, league, or a specific game so you only receive the notifications you need.

Note: WebSocket support requires a Pro or Enterprise subscription. Get your API key and connection URL from your dashboard.

How it works

  1. Get a token — POST to /api/websocket/auth with your API key. You receive a WebSocket URL and a short-lived token (1 hour).
  2. Connect — Open a WebSocket to the URL and pass the token (e.g. ?token=... or Authorization: Bearer ...).
  3. Subscribe — Send a subscribe message with an event type and optional filters (sport, league, eventId). You can subscribe to multiple event types and filter sets.
  4. Receive — The server pushes JSON messages when events occur. Each message has a type, timestamp, and data payload.

1. Get a WebSocket token

Call our auth endpoint with your API key. The response includes the WebSocket server URL and a token valid for 1 hour.

const response = await fetch('https://realtimesportsapi.com/api/websocket/auth', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
});
const { data } = await response.json();
// data.url  - WebSocket server URL (use wss:// in production)
// data.token - Token (expires in 1 hour)

2. Connect

Open a WebSocket to data.url and pass the token. For long tokens, some clients support Authorization: Bearer <token> on the handshake instead of the query string.

const ws = new WebSocket(`${data.url}?token=${data.token}`);

ws.onopen = () => console.log('Connected');
ws.onmessage = (e) => {
  const msg = JSON.parse(e.data);
  if (msg.type === 'pong' && msg.data?.message) console.log(msg.data.message);
  else if (msg.error) console.error(msg.error);
  else console.log(msg.type, msg.data);
};
ws.onclose = () => console.log('Disconnected');

3. Event types: what you can subscribe to

Choose one or more event types. You can use either the canonical or legacy name; both work the same.

Event typeAlso acceptedWhen you get notified
event_score_changescore_updateA score changes in a live game (goal, point, etc.)
event_liveA game transitions to live
event_status_changestatus_changeGame status changes (e.g. scheduled → in-progress → final)
event_playplay_eventA new play-by-play event (play, goal, card, etc.)
event_finalA game ends
event_odds_changeBetting odds for an event change significantly

4. Filtering: control what you receive

When you subscribe, you can omit filters to get all events of that type, or narrow by sport, league, and/or eventId. The more filters you set, the more specific the stream.

  • No filters — You receive every event of that type across all sports and leagues.
  • sport + league — Only events for that league (e.g. all NFL games, all Premier League games).
  • eventId — Only that single game. Use with sport/league if you want to be explicit.

Example sport / league values: football / nfl, basketball / nba, soccer / usa.1 or eng.1, hockey / nhl, baseball / mlb. Same values as in the REST API.

// All score changes, all sports
ws.send(JSON.stringify({ type: 'subscribe', event: 'event_score_change' }));

// Only NFL score changes
ws.send(JSON.stringify({
  type: 'subscribe',
  event: 'event_score_change',
  filters: { sport: 'football', league: 'nfl' }
}));

// Only one game (e.g. play-by-play for event 401772982)
ws.send(JSON.stringify({
  type: 'subscribe',
  event: 'event_play',
  filters: { sport: 'football', league: 'nfl', eventId: '401772982' }
}));

// Optional: throttle delivery (default is immediate)
// frequency: 'asap' | '30s' | '1m' | '5m' | '10m' | '30m'
ws.send(JSON.stringify({
  type: 'subscribe',
  event: 'event_score_change',
  filters: { sport: 'soccer', league: 'usa.1' },
  frequency: '30s'
}));

5. What you receive: message format

Every message from the server is JSON with type and timestamp. For event notifications, type matches the event type (e.g. event_score_change) and data contains the payload. Example score change:

{
  "type": "event_score_change",
  "timestamp": "2026-02-18T12:05:00.000Z",
  "data": {
    "eventId": "401772982",
    "sport": "football",
    "league": "nfl",
    "name": "Team A at Team B",
    "homeTeam": { "id": "...", "name": "Team B", "score": 14 },
    "awayTeam": { "id": "...", "name": "Team A", "score": 7 },
    "previousScore": { "home": 7, "away": 7 }
  }
}

Other server message types: subscribed / unsubscribed (after you subscribe/unsubscribe), pong (welcome or response to your ping), error (with error.code and error.message).

Keepalive: The server sends a WebSocket ping every 2 minutes so connections stay open behind proxies. If your client still disconnects after a few minutes, send { "type": "ping" } every 1–2 minutes; the server responds with pong.

6. Unsubscribe and full example

To stop receiving an event type, send unsubscribe with the same event and filters you used to subscribe.

class RealtimeSportsWebSocket {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.ws = null;
    this.token = null;
  }

  async connect() {
    const res = await fetch('https://realtimesportsapi.com/api/websocket/auth', {
      method: 'POST',
      headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' }
    });
    const { data } = await res.json();
    this.ws = new WebSocket(`${data.url}?token=${data.token}`);

    this.ws.onopen = () => {
      this.subscribe('event_score_change', { sport: 'football', league: 'nfl' });
      this.subscribe('event_play', { sport: 'football', league: 'nfl', eventId: '401772982' });
    };
    this.ws.onmessage = (e) => {
      const msg = JSON.parse(e.data);
      if (msg.type === 'event_score_change') console.log('Score:', msg.data);
      else if (msg.type === 'event_play') console.log('Play:', msg.data);
      else if (msg.type === 'error') console.error(msg.error);
    };
    this.ws.onclose = () => setTimeout(() => this.connect(), 5000);
  }

  subscribe(eventType, filters = {}, frequency = 'asap') {
    if (this.ws?.readyState === WebSocket.OPEN)
      this.ws.send(JSON.stringify({ type: 'subscribe', event: eventType, filters, frequency }));
  }
  unsubscribe(eventType, filters = {}) {
    if (this.ws?.readyState === WebSocket.OPEN)
      this.ws.send(JSON.stringify({ type: 'unsubscribe', event: eventType, filters }));
  }
  disconnect() { this.ws?.close(); }
}

const client = new RealtimeSportsWebSocket('YOUR_API_KEY');
client.connect();

Webhooks (Pro/Enterprise)

Receive real-time notifications when sports events occur. Webhooks send HTTP POST requests to your server when events happen, eliminating the need to poll our API.

Note: Webhooks are available for Pro and Enterprise subscriptions. Upgrade from your dashboard.

What are Webhooks?

Webhooks allow you to receive real-time notifications when events occur in sports games. Instead of polling our API, we send HTTP POST requests to your server when:

  • A game goes live
  • Scores change
  • Game status changes (scheduled → in-progress → final)
  • New plays occur
  • A game ends

Available Event Types

event.live

Triggered when a game goes live (status changes to in-progress)

event.score_change

Triggered when the score changes during a game

event.status_change

Triggered when game status changes (scheduled → in-progress → final)

event.play

Triggered when a new play occurs in a game

event.final

Triggered when a game ends (status changes to final)

Webhook Payload Format

Each webhook request includes the following headers and payload:

// Headers
X-Webhook-Signature: sha256=abc123...  // HMAC SHA256 signature
X-Webhook-Event: event.score_change     // Event type
Content-Type: application/json
User-Agent: RealtimeSportsAPI/1.0

// Payload
{
  "event": "event.score_change",
  "timestamp": "2024-01-15T20:30:00.000Z",
  "data": {
    "eventId": "401772982",
    "sport": "football",
    "league": "nfl",
    "homeTeam": {
      "id": "2",
      "name": "Kansas City Chiefs",
      "score": 24
    },
    "awayTeam": {
      "id": "3",
      "name": "Buffalo Bills",
      "score": 17
    },
    "status": {
      "type": {
        "id": "1",
        "name": "STATUS_IN_PROGRESS",
        "state": "in",
        "completed": false
      },
      "period": 3,
      "clock": {
        "value": 1200,
        "displayValue": "20:00"
      }
    }
  }
}

Signature Verification

Always verify webhook signatures to ensure requests are from Realtime Sports API. The signature is an HMAC SHA256 hash of the request body using your webhook secret.

// Node.js example
const crypto = require('crypto');

function verifyWebhookSignature(payload, signature, secret) {
  const expectedSignature = crypto
    .createHmac('sha256', secret)
    .update(JSON.stringify(payload))
    .digest('hex');
  
  const providedSignature = signature.replace('sha256=', '');
  
  return crypto.timingSafeEqual(
    Buffer.from(expectedSignature),
    Buffer.from(providedSignature)
  );
}

// In your webhook endpoint
app.post('/webhook', (req, res) => {
  const signature = req.headers['x-webhook-signature'];
  const secret = 'YOUR_WEBHOOK_SECRET'; // From webhook creation
  
  if (!verifyWebhookSignature(req.body, signature, secret)) {
    return res.status(401).send('Invalid signature');
  }
  
  // Process webhook
  const { event, data } = req.body;
  console.log(`Received ${event}:`, data);
  
  res.status(200).send('OK');
});

Complete Example

// Express.js webhook endpoint example
const express = require('express');
const crypto = require('crypto');
const app = express();

app.use(express.json());

// Your webhook secret (from webhook creation)
const WEBHOOK_SECRET = 'your-webhook-secret';

function verifySignature(payload, signature) {
  const expected = crypto
    .createHmac('sha256', WEBHOOK_SECRET)
    .update(JSON.stringify(payload))
    .digest('hex');
  
  const provided = signature.replace('sha256=', '');
  return crypto.timingSafeEqual(
    Buffer.from(expected),
    Buffer.from(provided)
  );
}

app.post('/webhook', (req, res) => {
  const signature = req.headers['x-webhook-signature'];
  const eventType = req.headers['x-webhook-event'];
  
  // Verify signature
  if (!verifySignature(req.body, signature)) {
    return res.status(401).json({ error: 'Invalid signature' });
  }
  
  const { event, timestamp, data } = req.body;
  
  // Handle different event types
  switch (event) {
    case 'event.live':
      console.log(`Game went live: ${data.name}`);
      // Notify users, update database, etc.
      break;
      
    case 'event.score_change':
      console.log(`Score update: ${data.awayTeam.name} ${data.awayTeam.score} - ${data.homeTeam.score} ${data.homeTeam.name}`);
      // Update scores in your app
      break;
      
    case 'event.status_change':
      console.log(`Status changed: ${data.status.type.name}`);
      // Update game status
      break;
      
    case 'event.play':
      console.log(`New play: ${data.play.text}`);
      // Display play in your app
      break;
      
    case 'event.final':
      console.log(`Game ended: Final score ${data.awayTeam.score} - ${data.homeTeam.score}`);
      // Show final results
      break;
  }
  
  // Always return 200 OK
  res.status(200).json({ received: true });
});

app.listen(3000, () => {
  console.log('Webhook server listening on port 3000');
});

Best Practices

  • ✓ Always verify webhook signatures to prevent unauthorized requests
  • ✓ Return 200 OK immediately, then process the webhook asynchronously
  • ✓ Use HTTPS for your webhook endpoint
  • ✓ Implement idempotency to handle duplicate deliveries
  • ✓ Set up retry logic for failed webhook deliveries
  • ✓ Monitor webhook delivery status in your dashboard
  • ✓ Keep your webhook secret secure and never expose it in client-side code

Python Example

import requests

API_KEY = 'YOUR_API_KEY'
BASE_URL = 'https://realtimesportsapi.com/api/v1'

class RealtimeSportsAPI:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = BASE_URL
        self.headers = {'Authorization': f'Bearer {api_key}'}
    
    def get_sports(self):
        """Get all available sports"""
        response = requests.get(f'{self.base_url}/sports', headers=self.headers)
        return response.json()['data']
    
    def get_leagues(self, sport):
        """Get leagues for a sport"""
        response = requests.get(
            f'{self.base_url}/sports/{sport}/leagues',
            headers=self.headers
        )
        return response.json()['data']
    
    def get_live_games(self, sport, league):
        """Get live games for a league"""
        response = requests.get(
            f'{self.base_url}/sports/{sport}/leagues/{league}/events/live',
            headers=self.headers
        )
        return response.json()['data']
    
    def get_plays(self, sport, league, event_id, page=1, limit=25):
        """Get plays for an event (paginated)"""
        response = requests.get(
            f'{self.base_url}/sports/{sport}/leagues/{league}/events/{event_id}/plays',
            params={'page': page, 'limit': limit},
            headers=self.headers
        )
        return response.json()

# Usage
api = RealtimeSportsAPI(API_KEY)

# Discover sports
sports = api.get_sports()
print(f"Available sports: {[s['name'] for s in sports]}")

# Get live NFL games
nfl_games = api.get_live_games('football', 'nfl')
for game in nfl_games:
    print(f"{game['name']}: {game['awayTeam']['score']} - {game['homeTeam']['score']}")

# Get plays with pagination
plays_response = api.get_plays('football', 'nfl', '401772982', page=1)
print(f"Page 1: {len(plays_response['data'])} plays")
print(f"Total: {plays_response['meta']['pagination']['total']} plays")
print(f"Total pages: {plays_response['meta']['pagination']['totalPages']}")