# Official MLB Team, Schedule & Stat Line Scraper (`dataspryva/official-mlb-team-schedule-and-stat-line-scraper`) Actor

Get baseball data from MLB's own public Stats API: season hitting, pitching, and fielding lines, team rosters, game schedules and scores, or live division standings. No authentication required.

- **URL**: https://apify.com/dataspryva/official-mlb-team-schedule-and-stat-line-scraper.md
- **Developed by:** [Dataspryva](https://apify.com/dataspryva) (community)
- **Categories:** Automation, Developer tools, Integrations
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.49 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
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?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Official MLB Team, Schedule & Stat Line Scraper

Pull Major League Baseball data straight from MLB's public Stats API. Get all 30 clubs, player bios and rosters, schedules with probable pitchers and final scores, division standings, season and career stat lines, player game logs, per-player box scores, league leaderboards, and ballpark reference data. Nine modes, one dataset, no API key, no login, and no proxy setup.

### What this actor does

- **Nine modes in one actor** — teams, players/rosters, player stats, game logs, schedule, standings, box scores, leaders, and reference data.
- **Complete player pool** — season stats include every player the source returns, not only qualified hitters or pitchers.
- **Historical coverage** — stats reach back to 1876 and schedules to 1901; request one season or several in the same run.
- **Game-level detail** — schedules include probable pitchers, weather, decisions, attendance, umpires, and inning line scores; box scores return per-player batting, pitching, or fielding lines.
- **Clean, flat records** — every record carries a `recordType` and `scrapedAt`; fields the source does not have for a record are omitted rather than sent as null.

### Modes

| Mode | One record per | Highlights |
|---|---|---|
| `getTeams` | Club | League, division, venue, franchise, logo, team URL |
| `getPlayers` | Player | Bio, position, bats/throws, debut, headshot, team; rosters and name search; optional season stats |
| `getPlayerStats` | Player stat split | Season, career, season-by-season, month, day-of-week, home/away, or date-range lines |
| `getGameLog` | Player per game | One row per game with the full stat line, opponent, and game ID |
| `getSchedule` | Game | Scores, status, probable pitchers, weather, decisions, attendance, umpires, line score |
| `getStandings` | Team season record | Wins, losses, pct, ranks, games back, streaks, splits, clinch and elimination numbers |
| `getBoxscore` | Player per game | Batting, pitching, or fielding line plus game context; optional team totals and line score |
| `getLeaders` | Ranked player | Category, rank, value, player, team, league |
| `getReference` | Venue / league / division / season | Ballpark capacity, surface, roof, coordinates, league and division metadata, season calendar |

### Output per record type

#### Team (`getTeams`)

`recordType`, `teamId`, `name`, `abbreviation`, `teamName`, `shortName`, `locationName`, `clubName`, `franchiseName`, `firstYearOfPlay`, `teamCode`, `fileCode`, `leagueName`, `leagueId`, `divisionName`, `divisionId`, `venueName`, `venueId`, `sportName`, `springLeagueName`, `allStarStatus`, `active`, `season`, `logoUrl`, `mlbUrl`, `scrapedAt`.

#### Player (`getPlayers`)

`recordType`, `playerId`, `fullName`, `firstName`, `lastName`, `middleName`, `useName`, `primaryNumber`, `birthDate`, `currentAge`, `birthCity`, `birthStateProvince`, `birthCountry`, `height`, `weight`, `active`, `primaryPosition`, `primaryPositionCode`, `primaryPositionType`, `batSide`, `pitchHand`, `mlbDebutDate`, `draftYear`, `nickName`, `nameSlug`, `boxscoreName`, `currentTeam`, `currentTeamId`, `leagueName`, `divisionName`, `headshotUrl`, `mlbUrl`, `season`. Roster rows also include `jerseyNumber`, `rosterStatus`, `parentTeamId`, `rosterPosition`, and `rosterPositionAbbreviation`. With `includeStats`, a `stats` object holds the selected stat group.

#### Player stats (`getPlayerStats`)

`recordType`, `playerId`, `playerName`, `fullName`, `firstName`, `lastName`, `teamId`, `teamName`, `position`, `positionAbbreviation`, `leagueName`, `sportId`, `season`, `statType`, `statGroup`, `splitKey`, `splitValue`, `month`, `monthName`, `dayOfWeek`, `dayOfWeekName`, `isHome`, `situationCode`, `startDate`, `endDate`, `mlbUrl`. Every non-empty stat field returned by MLB is included, for example: `gamesPlayed`, `atBats`, `runs`, `hits`, `doubles`, `triples`, `homeRuns`, `rbi`, `baseOnBalls`, `walks`, `strikeOuts`, `strikeouts`, `stolenBases`, `caughtStealing`, `avg`, `battingAverage`, `obp`, `onBasePercentage`, `slg`, `sluggingPct`, `ops`, `babip`, `wins`, `losses`, `saves`, `holds`, `blownSaves`, `inningsPitched`, `earnedRuns`, `era`, `whip`, `battersFaced`, `numberOfPitches`, `completeGames`, `shutouts`, `strikeoutsPer9Inn`, `walksPer9Inn`, `fieldingPercentage`, `chances`, `putOuts`, `assists`, `errors`, `doublePlays`.

#### Game log (`getGameLog`)

`recordType`, `playerId`, `playerName`, `fullName`, `teamId`, `teamName`, `opponentId`, `opponentName`, `isHome`, `gamePk`, `officialDate`, `date`, `season`, `gameType`, `statGroup`, `mlbUrl`, plus every non-empty stat field for that game.

#### Game (`getSchedule`)

`recordType`, `gamePk`, `gameGuid`, `season`, `gameDate`, `officialDate`, `gameType`, `gameNumber`, `doubleHeader`, `dayNight`, `seriesDescription`, `seriesGameNumber`, `gamesInSeries`, `scheduledInnings`, `isTie`, `recordSource`, `publicFacing`, `status`, `abstractGameState`, `codedGameState`, `statusCode`, `homeTeam`, `homeTeamId`, `homeTeamAbbreviation`, `awayTeam`, `awayTeamId`, `awayTeamAbbreviation`, `homeScore`, `awayScore`, `homeWinner`, `awayWinner`, `venue`, `venueId`, `awayProbablePitcher`, `awayProbablePitcherId`, `homeProbablePitcher`, `homeProbablePitcherId`, `weatherCondition`, `weatherTemp`, `weatherWind`, `awayRuns`, `homeRuns`, `awayHits`, `homeHits`, `awayErrors`, `homeErrors`, `innings`, `winningPitcher`, `winningPitcherId`, `losingPitcher`, `losingPitcherId`, `savePitcher`, `savePitcherId`, `attendance`, `firstPitch`, `gameDurationMinutes`, `delayDurationMinutes`, `officials`, `noHitter`, `perfectGame`, `mlbUrl`, `scrapedAt`.

#### Standing (`getStandings`)

`recordType`, `teamName`, `teamId`, `leagueName`, `leagueId`, `divisionName`, `divisionId`, `season`, `wins`, `losses`, `gamesPlayed`, `pct`, `divisionRank`, `leagueRank`, `sportRank`, `wildCardRank`, `gamesBack`, `wildCardGamesBack`, `leagueGamesBack`, `sportGamesBack`, `divisionGamesBack`, `streakCode`, `streakType`, `streakNumber`, `runsScored`, `runsAllowed`, `runDifferential`, `clinched`, `divisionChamp`, `divisionLeader`, `hasWildcard`, `clinchIndicator`, `magicNumber`, `eliminationNumber`, `wildCardEliminationNumber`, `homeRecord`, `awayRecord`, `lastTenRecord`, `overallRecord`, `leagueRecord`, `divisionRecord`, `mlbUrl`, `scrapedAt`.

#### Box score (`getBoxscore`)

`recordType` (`battingLine`, `pitchingLine`, `fieldingLine`), `statGroup`, `gamePk`, `season`, `gameDate`, `officialDate`, `gameType`, `status`, `homeTeam`, `homeTeamId`, `awayTeam`, `awayTeamId`, `homeScore`, `awayScore`, `venue`, `attendance`, `weatherCondition`, `weatherWind`, `firstPitch`, `gameDurationMinutes`, `winningPitcher`, `losingPitcher`, `savePitcher`, `isHome`, `teamName`, `teamId`, `playerId`, `playerName`, `fullName`, `jerseyNumber`, `position`, `battingOrder`, `summary`, `decision`, `mlbUrl`, and every non-empty stat field for the selected group. When games come from `gamePks`, only fields the boxscore payload carries are present (for example `officialDate`, not `gameDate`, `gameType`, or `status`). `seasonBattingAverage`, `seasonOnBasePercentage`, `seasonSluggingPct`, `seasonOps`, `seasonEra`, and `seasonWhip` add season context. With `includeTeamTotals`, `teamGame` records add `teamStats` and `lineScore`.

#### Leader (`getLeaders`)

`recordType`, `leaderCategory`, `statGroup`, `season`, `gameType`, `gameTypeDescription`, `rank`, `value`, `playerId`, `playerName`, `teamId`, `teamName`, `leagueName`, `sportId`, `mlbUrl`, `scrapedAt`.

#### Reference (`getReference`)

- Venue: `recordType`, `venueId`, `name`, `active`, `season`, `city`, `state`, `stateAbbrev`, `postalCode`, `country`, `address`, `phone`, `latitude`, `longitude`, `azimuthAngle`, `elevation`, `capacity`, `turfType`, `roofType`, outfield distances (`leftLine`, `left`, `leftCenter`, `center`, `rightCenter`, `right`, `rightLine`).
- League: `recordType`, `leagueId`, `name`, `abbreviation`, `nameShort`, `seasonState`, `hasWildCard`, `hasSplitSeason`, `numGames`, `numTeams`, `numWildcardTeams`, and season calendar dates.
- Division: `recordType`, `divisionId`, `name`, `nameShort`, `abbreviation`, `leagueId`, `leagueName`, `sportId`, `hasWildcard`, `active`, `sortOrder`, `numPlayoffTeams`.
- Season: `recordType`, `seasonId`, `hasWildcard`, and the full MLB season calendar (`regularSeasonStartDate`, `regularSeasonEndDate`, `postSeasonStartDate`, `postSeasonEndDate`, and related dates).

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `mode` | string | `getPlayerStats` | `getTeams`, `getPlayers`, `getPlayerStats`, `getGameLog`, `getSchedule`, `getStandings`, `getBoxscore`, `getLeaders`, `getReference` |
| `seasons` | array | – | Season years, e.g. `2026`; multiple seasons allowed |
| `teamIds` | array | all teams | MLB team IDs, names, abbreviations, or team URLs (e.g. `147`, `Yankees`, `NYY`) |
| `playerIds` | array | – | MLB player IDs, e.g. `660271` |
| `gamePks` | array | – | MLB game IDs for `getBoxscore` |
| `startDate` | string | – | `YYYY-MM-DD` for schedules, box scores, or date-range stats |
| `endDate` | string | – | `YYYY-MM-DD` for schedules, box scores, or date-range stats |
| `statGroup` | string | `hitting` | `hitting`, `pitching`, or `fielding` |
| `statType` | string | `season` | `season`, `career`, `yearByYear`, `byMonth`, `byDayOfWeek`, `homeAndAway`, `byDateRange` |
| `rosterType` | string | `active` | `active`, `40Man`, `fullSeason`, `depthChart`, `coach` |
| `searchQuery` | string | – | Player name search for `getPlayers`, e.g. `Ohtani` |
| `leagueId` | string | `both` | `both`, `AL`, or `NL` for standings and leaders |
| `gameType` | string | `R` | `S`, `R`, `F`, `D`, `L`, `W`, `C`, `P`, `A`, `I`, `E` |
| `leaderCategory` | string | `homeRuns` | Category for `getLeaders`, e.g. `homeRuns`, `battingAverage`, `earnedRunAverage`, `saves` |
| `referenceType` | string | `venues` | `venues`, `leagues`, `divisions`, or `seasons` |
| `includeStats` | boolean | `false` | Add season stats to `getPlayers` rows |
| `includeTeamTotals` | boolean | `false` | Add team totals and line score to `getBoxscore` |
| `maxItems` | integer | `50` | Hard cap on records (1–10,000) |

### Examples

#### A team's roster with season stats

```json
{
  "mode": "getPlayers",
  "seasons": ["2026"],
  "teamIds": ["Yankees"],
  "rosterType": "active",
  "includeStats": true,
  "maxItems": 40
}
```

#### A week of games with probable pitchers and decisions

```json
{
  "mode": "getSchedule",
  "startDate": "2026-06-01",
  "endDate": "2026-06-07",
  "gameType": "R",
  "maxItems": 100
}
```

#### Season pitching stats for two players

```json
{
  "mode": "getPlayerStats",
  "seasons": ["2024", "2025"],
  "playerIds": ["660271", "592450"],
  "statGroup": "pitching",
  "statType": "season",
  "maxItems": 20
}
```

#### A box score with per-player lines and team totals

```json
{
  "mode": "getBoxscore",
  "gamePks": ["822974"],
  "statGroup": "hitting",
  "includeTeamTotals": true,
  "maxItems": 50
}
```

### Use cases

- **Fantasy baseball** — pull rosters, season lines, and per-game logs for lineup decisions.
- **Betting and prediction models** — backtest with schedules, scores, probable pitchers, and box scores.
- **Sports apps and dashboards** — power scoreboards, standings tables, and player pages.
- **Analytics and research** — join stable MLB IDs across seasons, teams, and games.
- **Media and newsletters** — generate recaps, leaderboards, and matchup previews.
- **Data engineering** — build clean historical datasets with one record type per row.

### FAQ

#### Is this an official MLB product?

No. This is an independent, third-party actor that reads MLB's public Stats API. It is not affiliated with, endorsed by, or sponsored by Major League Baseball or any club.

#### Do I need an API key, login, or proxy?

No. The public Stats API needs no key or account, and the actor does not require a proxy.

#### How far back does the data go?

Player stats go back to 1876 and schedules to 1901 in the source. Early seasons have fewer recorded fields; those fields are omitted when the source does not have them.

#### What is the difference between `getPlayerStats`, `getGameLog`, and `getBoxscore`?

`getPlayerStats` returns season, career, or split totals. `getGameLog` returns one row per player per game. `getBoxscore` returns every player's batting, pitching, or fielding line from one game, plus game context.

#### Why are some fields missing from a record?

The API does not publish every field for every player, game, or season. Empty fields are omitted rather than filled with placeholders.

#### Why is there no save pitcher on some games?

A save only exists when the game situation creates one. Games without a save omit `savePitcher`.

#### Can I request several seasons or teams at once?

Yes. Put multiple years in `seasons` and multiple IDs, names, or team URLs in `teamIds`. Duplicate rows are removed by MLB IDs.

#### Which seasons need player or team IDs for splits?

Season, career, and date-range stats work for the full player pool. Date-range stats take their seasons from `startDate`/`endDate`, so the dates and `seasons` do not disagree. Season-by-season, month, day-of-week, and home/away splits require `playerIds` or `teamIds` because they are per-player views in the source.

#### Will my existing tasks keep working?

Yes. Existing modes and output fields are preserved. Older tasks that send `season` or `teamId` are still accepted and mapped to the new fields.

#### Are doubleheaders handled?

Yes. Games are de-duplicated by `gamePk`, so both games of a doubleheader are kept.

### Data source

The actor reads `statsapi.mlb.com`, the public JSON feed behind MLB.com and the MLB app. It is an undocumented public API; endpoint behavior and field availability can change. Use the data in accordance with MLB's terms and any applicable law.

# Actor input Schema

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

What to fetch. Nine modes cover teams, players/rosters, player stats, game logs, schedules, standings, box scores, leaders, and reference data.

## `seasons` (type: `array`):

Season years, e.g. 2024 or 2025. Leave empty for the current season. Stats cover 1876 onward; schedules cover 1901 onward. Multiple seasons can be fetched in one run (mode=getTeams, getPlayers, getPlayerStats, getSchedule, getStandings, getLeaders, getReference).

## `teamIds` (type: `array`):

Filter by MLB team IDs (147 = Yankees), team names (Yankees), abbreviations (NYY), or team URLs (https://www.mlb.com/yankees). Leave empty for all teams. Used by teams, players, player stats, schedule, standings, box score, and leaders modes.

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

MLB player IDs, e.g. 660271 for Shohei Ohtani. Used by players, player stats, and game log modes. Use Search query to find a player ID by name.

## `gamePks` (type: `array`):

MLB game IDs (gamePk), e.g. 822974. Used by mode=getBoxscore. Leave empty to derive games from seasons, dates, or teams.

## `startDate` (type: `string`):

Start date in YYYY-MM-DD format. Used by schedule, box score, and player stats (statType=byDateRange). A single date can be set in either date field.

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

End date in YYYY-MM-DD format. Used by schedule, box score, and player stats (statType=byDateRange).

## `statGroup` (type: `string`):

Which stat category to return for players, player stats, game logs, box scores, and leaders.

## `statType` (type: `string`):

Scope for mode=getPlayerStats. Season, career, and date-range stats work for the whole player pool; season-by-season, month, day-of-week, and home/away splits require playerIds or teamIds.

## `rosterType` (type: `string`):

Which roster to return for mode=getPlayers when teamIds is set.

## `searchQuery` (type: `string`):

Find players by name for mode=getPlayers, e.g. Ohtani or Aaron Judge. Returns up to 50 matching players.

## `leagueId` (type: `string`):

Filter standings and leaders to the American League, National League, or both.

## `gameType` (type: `string`):

Filter games and stats by game type. Regular season is R; other codes include spring training (S), wild card (F), division series (D), league championship (L), World Series (W), and All-Star (A).

## `leaderCategory` (type: `string`):

Stat category for mode=getLeaders. Choose a category that belongs to the selected stat group, e.g. homeRuns, battingAverage, or runsBattedIn for hitting; earnedRunAverage, strikeouts, or saves for pitching; fieldingPercentage or errors for fielding.

## `referenceType` (type: `string`):

Which reference dataset to return for mode=getReference.

## `includeStats` (type: `boolean`):

For mode=getPlayers, attach each player's season stats for the selected stat group.

## `includeTeamTotals` (type: `boolean`):

For mode=getBoxscore, add one team-total record per side per game, including the inning-by-inning line score.

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

Hard cap on the number of records returned (1–10,000).

## Actor input object example

```json
{
  "mode": "getPlayers",
  "seasons": [],
  "teamIds": [],
  "playerIds": [],
  "gamePks": [],
  "statGroup": "hitting",
  "statType": "season",
  "rosterType": "active",
  "leagueId": "both",
  "gameType": "R",
  "leaderCategory": "homeRuns",
  "referenceType": "venues",
  "includeStats": false,
  "includeTeamTotals": false,
  "maxItems": 3
}
```

# Actor output Schema

## `mlbData` (type: `string`):

Dataset containing the requested MLB records, tagged by recordType.

# 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 = {
    "mode": "getPlayers",
    "seasons": [],
    "teamIds": [],
    "playerIds": [],
    "gamePks": [],
    "statGroup": "hitting",
    "statType": "season",
    "rosterType": "active",
    "leagueId": "both",
    "gameType": "R",
    "leaderCategory": "homeRuns",
    "referenceType": "venues",
    "includeStats": false,
    "includeTeamTotals": false,
    "maxItems": 3
};

// Run the Actor and wait for it to finish
const run = await client.actor("dataspryva/official-mlb-team-schedule-and-stat-line-scraper").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 = {
    "mode": "getPlayers",
    "seasons": [],
    "teamIds": [],
    "playerIds": [],
    "gamePks": [],
    "statGroup": "hitting",
    "statType": "season",
    "rosterType": "active",
    "leagueId": "both",
    "gameType": "R",
    "leaderCategory": "homeRuns",
    "referenceType": "venues",
    "includeStats": False,
    "includeTeamTotals": False,
    "maxItems": 3,
}

# Run the Actor and wait for it to finish
run = client.actor("dataspryva/official-mlb-team-schedule-and-stat-line-scraper").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 '{
  "mode": "getPlayers",
  "seasons": [],
  "teamIds": [],
  "playerIds": [],
  "gamePks": [],
  "statGroup": "hitting",
  "statType": "season",
  "rosterType": "active",
  "leagueId": "both",
  "gameType": "R",
  "leaderCategory": "homeRuns",
  "referenceType": "venues",
  "includeStats": false,
  "includeTeamTotals": false,
  "maxItems": 3
}' |
apify call dataspryva/official-mlb-team-schedule-and-stat-line-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,dataspryva/official-mlb-team-schedule-and-stat-line-scraper"
        }
    }
}
```

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/rg2FBxNB1s8X13GRi/builds/cCMwmOrwZkNoObEE3/openapi.json
