# MLB & NHL Stats API — Scores, Standings, Box Scores (`lizaraco/mlb-nhl-stats-api`) Actor

Live scores, schedules, standings, box scores, player stats and league leaders for MLB and NHL from the leagues' OFFICIAL public APIs — one normalized schema across both. No scraping, no login, no proxies: this keeps working all season.

- **URL**: https://apify.com/lizaraco/mlb-nhl-stats-api.md
- **Developed by:** [Shawn Downs](https://apify.com/lizaraco) (community)
- **Categories:** AI, Agents, Automation
- **Stats:** 2 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.40 / 1,000 games

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## MLB & NHL Stats API — Live Scores, Standings, Box Scores

Live scores, schedules, standings, box scores, player stats and league leaders for
**MLB and NHL**, pulled from the leagues' **official public APIs** and returned in **one
normalized schema** across both sports. No scraping, no login, no proxies — which means
it doesn't break mid-season the way sports-site scrapers do.

### Modes

| mode | what you get | one row per |
|---|---|---|
| `games` | schedule + live scores for a date or range (≤31 days): status, score, inning/period, clock, winner | game |
| `standings` | current or dated table: W-L(-OTL), points / win%, games back, run/goal diff, streak, rank | team |
| `boxscore` | team lines + every player's line (batting/pitching or skater/goalie) for explicit game IDs or all final games on a date | team + player |
| `leaders` | top 25 per category — MLB: `homeRuns`, `battingAverage`, `earnedRunAverage`, `strikeouts`, `stolenBases`…; NHL: `goals`, `assists`, `points`, `plusMinus`, `wins`, `savePctg`, `gaa`, `shutouts` | leader |
| `player-stats` | season line for MLB person IDs / NHL player IDs | player |

Set `league` to `mlb`, `nhl`, or `both`. An off-season league simply returns no games.

### Why official APIs matter

Most sports actors scrape ESPN, Flashscore or Sofascore — sites that actively block
automated traffic and change markup every season. This actor reads
`statsapi.mlb.com` and `api-web.nhle.com`, the same endpoints the leagues' own apps use.
Stable for years, free, and fast (a full slate of games returns in under a second).

### Examples

- Today's scores, both leagues: `{}` (that's the default input)
- NHL opening week: `{"league":"nhl","mode":"games","date":"2026-10-07","endDate":"2026-10-13"}`
- MLB playoff box scores: `{"league":"mlb","mode":"boxscore","date":"2026-10-03"}`
- Home-run and goal leaders: `{"mode":"leaders","categories":["homeRuns","goals"]}`

### Output

Typed rows (`type` = `game` / `standing` / `boxscore_team` / `boxscore_player` / `leader` /
`player_stats`) with a shared column set; sport-specific columns are simply empty for the
other league. Full field list in the Output tab.

### Pricing

Pay per event: `game` rows $2/1,000, `stat-row` rows (standings, leaders, player lines)
$0.50/1,000, plus a $0.005 start fee. Error rows are never charged. `maxItems` caps the
run (and your spend).

### Use with AI agents

MCP-friendly: an agent asks "who's leading the AL East and what's the score in the Yankees
game?" and gets clean JSON in one call — no per-site glue, no HTML.

# Actor input Schema

## `league` (type: `string`):

Which league(s) to pull. Off-season leagues simply return no games.

## `mode` (type: `string`):

games: one row per game with status, score and period/inning. standings: one row per team. boxscore: team + player rows per game. leaders: top players per category. player-stats: season lines for playerIds.

## `date` (type: `string`):

Date for games / boxscore / standings. Blank = today (UTC).

## `endDate` (type: `string`):

games mode only: pull every day from date to endDate (max 31 days).

## `season` (type: `string`):

MLB: year (2026). NHL: eight digits (20252026). Blank = current season.

## `gameIds` (type: `array`):

Explicit game IDs (MLB gamePk / NHL game id). Blank = all final games on the date.

## `playerIds` (type: `array`):

MLB person IDs / NHL player IDs.

## `categories` (type: `array`):

leaders mode. MLB e.g. homeRuns, battingAverage, earnedRunAverage, strikeouts, stolenBases. NHL skaters: goals, assists, points, plusMinus; goalies: wins, savePctg, gaa, shutouts.

## `maxItems` (type: `integer`):

Hard cap on dataset rows (also caps your charge).

## Actor input object example

```json
{
  "league": "both",
  "mode": "games",
  "categories": [
    "homeRuns",
    "goals"
  ],
  "maxItems": 2000
}
```

# Actor output Schema

## `results` (type: `string`):

All result rows produced by this run.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "categories": [
        "homeRuns",
        "goals"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("lizaraco/mlb-nhl-stats-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "categories": [
        "homeRuns",
        "goals",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("lizaraco/mlb-nhl-stats-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "categories": [
    "homeRuns",
    "goals"
  ]
}' |
apify call lizaraco/mlb-nhl-stats-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,lizaraco/mlb-nhl-stats-api"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/aI2VYlbBbwXQUf2N0/builds/pJMHr9VORBwdORiUe/openapi.json
