# MLB Stats Scraper — Teams, Rosters, Schedules & Players (`hipersoft/mlb-statsapi-scraper`) Actor

Fetch MLB baseball data in bulk — teams, rosters, schedules, scores and player profiles. One clean row per team, roster spot, game or player with names, leagues, divisions, venues, scores and bios. Fast and reliable for sports apps, stats dashboards, fantasy tools and n8n.

- **URL**: https://apify.com/hipersoft/mlb-statsapi-scraper.md
- **Developed by:** [hiper soft](https://apify.com/hipersoft) (community)
- **Categories:** Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.0005 / item scraped

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 Stats Scraper — Teams, Rosters, Schedules, Scores & Players

MLB Stats Scraper pulls **teams, rosters, schedules, scores and player profiles** for Major League Baseball — all as clean, structured data. List every MLB club for a season, get the full roster for a team, pull games and results for any date or date range, and look up player bios by id or name. Export to JSON, CSV, Excel or XML. Fast, reliable, and built for sports apps, stats dashboards, fantasy tools and automation workflows.

### What does this MLB scraper do?

Pick a **mode**, add a couple of parameters, and it returns every matching record as structured data:

- **Teams** — every MLB club for a season, with league, division, venue, city and the year the franchise started play.
- **Roster** — all players on a team for a season, with position, jersey number and team id.
- **Schedule** — games for a single date or a date range, with home/away teams, scores, status and venue.
- **Player** — a single player profile by id, or a name search, with position, bat side, throwing hand, birth date, birth country and MLB debut date.

### What data can you get?

| Data point | Description |
| --- | --- |
| Team | `id`, `name`, `abbreviation`, `league`, `division`, `venue`, `city`, `firstYearOfPlay` |
| Roster | `playerId`, `name`, `position`, `jerseyNumber`, `teamId` |
| Schedule | `gamePk`, `date`, `homeTeam`, `awayTeam`, `homeScore`, `awayScore`, `status`, `venue` |
| Player | `id`, `name`, `primaryPosition`, `batSide`, `throws`, `birthDate`, `birthCountry`, `mlbDebutDate` |

### What you get

Each team, roster spot, game or player is one clean dataset record. Every row carries a `recordType` so you can tell them apart. Export the full table to JSON, CSV, Excel or XML, or pull it programmatically.

```json
{
  "mode": "teams",
  "recordType": "team",
  "id": 147,
  "name": "New York Yankees",
  "abbreviation": "NYY",
  "league": "American League",
  "division": "American League East",
  "venue": "Yankee Stadium",
  "city": "Bronx",
  "firstYearOfPlay": "1903"
}
```

### Use cases

- Build team directories and league/division tables for a baseball site or app.
- Pull daily schedules and final scores into a dashboard or calendar.
- Backfill results across a date range for a stats or analytics dataset.
- Enrich fantasy tools with roster positions, jersey numbers and player bios.
- Power a bot that reports last night's games and scores.

### How to use the MLB Stats Scraper

1. Add the MLB Stats Scraper to your Apify account and open its input.
2. Choose a **mode**: teams, roster, schedule or player.
3. Fill the matching parameter — `season` for teams/roster, `teamId` for roster, `date` (or `startDate` + `endDate`) for schedule, or `playerId` / `playerName` for player.
4. Click **Run**.
5. Export the results as JSON, CSV, Excel or XML, or pull them via the Apify API.

### Input

```json
{
  "mode": "teams",
  "season": 2025
}
```

| Field | Description |
| --- | --- |
| `mode` | `teams`, `roster`, `schedule` or `player`. |
| `season` | Four-digit year for `teams` and `roster` (e.g. 2025). Defaults to the current year. |
| `teamId` | Numeric team id for `roster` (e.g. 147 for the Yankees). |
| `date` | Single date for `schedule` (YYYY-MM-DD). |
| `startDate` / `endDate` | Date range for `schedule` (YYYY-MM-DD). |
| `playerId` | Numeric player id for `player` (e.g. 545361). |
| `playerName` | Player name to search for `player` (e.g. "Mike Trout"). |

### Tip: chaining modes

Don't know an id? Run `teams` to list every club and its id, `roster` to get player ids for a team, then feed a `playerId` into `player` for the full profile — or a `teamId` into `roster` for the squad.

### Output schema

Fields below are for the `teams` mode. The roster, schedule and player modes return their own record shapes, and each row carries a `recordType` so you can tell them apart.

| Field | Type | Description |
| --- | --- | --- |
| `mode` | string | The mode that produced the record. |
| `recordType` | string | `team`, `rosterPlayer`, `game` or `player`. |
| `id` | integer | Unique identifier for the team. |
| `name` | string | Team name (e.g. "New York Yankees"). |
| `abbreviation` | string | Short team code (e.g. "NYY"). |
| `league` | string | League name (American or National League). |
| `division` | string | Division name (e.g. "American League East"). |
| `venue` | string | Home ballpark. |
| `city` | string | Team location / city. |
| `firstYearOfPlay` | string | Year the franchise started play. |

### Need more sports & media data?

- [Sports Data Scraper (TheSportsDB)](https://apify.com/hipersoft/thesportsdb-scraper) — teams, fixtures, results and players across many sports.
- [ESPN Sports Scraper](https://apify.com/hipersoft/espn-sports-scraper) — live scores, teams, standings and news.
- [TVmaze Scraper](https://apify.com/hipersoft/tvmaze-scraper) — TV shows, episodes and cast data.

### FAQ

**Which league and seasons are covered?**
Major League Baseball, across current and historical seasons. Pass any four-digit `season` year to the teams and roster modes, and any date to the schedule mode.

**How do I find a team or player id?**
Run the `teams` mode to list every club and its id, then run `roster` for a team to get player ids. You can also search a player by name with `playerName`.

**What export formats are supported?**
JSON, CSV, Excel and XML, plus programmatic access through the Apify API.

**How does billing work?**
You pay per item you get, so cost scales with the number of records you actually collect. See the **Pricing** tab for current rates.

**Can I use this with n8n?**
Yes. Run the MLB Stats Scraper from [n8n](https://n8n.io) with the Apify node — trigger a run, pass your `mode` and parameters, and read the dataset items straight into your workflow. It also works with Make, Zapier and the Apify API.

**Can I connect this to other tools?**
The MLB Stats Scraper connects with almost any cloud service or web app thanks to [integrations on the Apify platform](https://apify.com/integrations). It works with [Make](https://apify.com/integrations/make), [Zapier](https://apify.com/integrations/zapier), [Slack](https://docs.apify.com/platform/integrations/slack), [Airbyte](https://docs.apify.com/platform/integrations/airbyte), [GitHub](https://docs.apify.com/platform/integrations/github), [Google Drive](https://docs.apify.com/platform/integrations/drive) and [many more](https://apify.com/integrations), plus the [Apify API](https://docs.apify.com/api/v2), JavaScript/Python clients and MCP. Or use [webhooks](https://docs.apify.com/platform/integrations/webhooks) to trigger an action whenever a run finishes.

### Related Actors

- [Sports Data Scraper (TheSportsDB)](https://apify.com/hipersoft/thesportsdb-scraper)
- [ESPN Sports Scraper](https://apify.com/hipersoft/espn-sports-scraper)
- [TVmaze Scraper](https://apify.com/hipersoft/tvmaze-scraper)

### Notes

Original clean-room implementation. Reads only publicly available baseball information. Not affiliated with, endorsed by or connected to Major League Baseball, MLB Advanced Media or any club.

# Actor input Schema

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

What to fetch: teams (all MLB teams for a season), roster (all players on a team for a season), schedule (games, scores and status for a date or date range), or player (a single player profile by id, or search by name).

## `season` (type: `integer`):

Four-digit year used by teams and roster (e.g. 2025). Defaults to the current year when left empty.

## `teamId` (type: `integer`):

Numeric MLB team id used by the roster mode (e.g. 147 for the New York Yankees, 133 for the Athletics). Run the teams mode first to look ids up.

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

Single date for the schedule mode, e.g. 2025-07-04. Ignored if Start date and End date are both set.

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

Start of a date range for the schedule mode, e.g. 2025-07-01. Use together with End date to pull multiple days of games.

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

End of a date range for the schedule mode, e.g. 2025-07-07. Use together with Start date.

## `playerId` (type: `integer`):

Numeric MLB player id for the player mode (e.g. 545361 for Mike Trout). Takes priority over Player name if both are set. Find ids via the roster mode.

## `playerName` (type: `string`):

Player name to search in the player mode when you do not have the id (e.g. "Mike Trout"). Ignored if Player ID is set.

## Actor input object example

```json
{
  "mode": "teams",
  "season": 2025,
  "teamId": 147,
  "date": "2025-07-04",
  "startDate": "2025-07-01",
  "endDate": "2025-07-07",
  "playerId": 545361,
  "playerName": "Mike Trout"
}
```

# Actor output Schema

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

The results as dataset items.

# 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 = {
    "season": 2025
};

// Run the Actor and wait for it to finish
const run = await client.actor("hipersoft/mlb-statsapi-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 = { "season": 2025 }

# Run the Actor and wait for it to finish
run = client.actor("hipersoft/mlb-statsapi-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 '{
  "season": 2025
}' |
apify call hipersoft/mlb-statsapi-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,hipersoft/mlb-statsapi-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/E3k3dWcWIbSNc366r/builds/95T88lcxsisdbqxGL/openapi.json
