The MLB REST API is the easiest way to gather statistics and information about Major League Baseball players.

Please see the official API documentation on RapidAPI for the complete, up-to-date specification.

Overview

The MLB REST API is a full-featured service for gathering current player statistics for Major League Baseball. It is hosted on RapidAPI, and allows for different calls to be made based on what your needs are.

The API is perfect for pulling stats for the following use cases:

  • Fantasy baseball websites that need current stats for the season
  • Sports news sites that want to pull current player statistics and display in the page
  • Baseball enthusiast sites that want up-to-date player performance data

Key Features

  • Player Search: Fuzzy search across player names, teams, and positions
  • Batter Statistics: Comprehensive batting stats including AVG, OBP, SLG, and more
  • Pitcher Statistics: Complete pitching stats including ERA, WHIP, K/9, and more
  • Batch Queries: Fetch stats for up to 10 players in a single request

Getting Started

Requests go through RapidAPI, so every call needs your RapidAPI key. Subscribe to the API on RapidAPI to get one, then send it with each request:

Terminal window
curl "https://mlb-statistics-api.p.rapidapi.com/search?q=mike+trout" \
-H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
-H "X-RapidAPI-Host: mlb-statistics-api.p.rapidapi.com"

Each player in the system has a unique id that can be used to identify the player on subsequent API calls. Each player also has a slug attached to them, which is more human-readable but not absolutely guaranteed to be unique. You can use either the id or slug to query player statistics.

All statistics endpoints return a modified timestamp indicating when the data was last refreshed (in UTC). You can use this to determine how fresh the data is.

Endpoints

Search for Players

GET /search?q={search-criteria}

Searches for a player by name, team, or position. Returns up to 10 matching results.

Example:

GET /search?q=mike+trout

Get Batter Statistics

GET /stats/batters/{id-or-slug}

Gets batting statistics for a single player. Accepts either player ID or slug.

Examples:

GET /stats/batters/i49fu # By ID
GET /stats/batters/mike-trout # By slug

Get Pitcher Statistics

GET /stats/pitchers/{id-or-slug}

Gets pitching statistics for a single player. Accepts either player ID or slug.

Examples:

GET /stats/pitchers/j3k8e # By ID
GET /stats/pitchers/shohei-ohtani # By slug

Get Multiple Batters

GET /stats/batters?ids={id1,id2,...}

Gets batting stats for up to 10 players at a time. IDs/slugs are comma-separated.

Example:

GET /stats/batters?ids=i49fu,idh13,mookie-betts

Get Multiple Pitchers

GET /stats/pitchers?ids={id1,id2,...}

Gets pitching stats for up to 10 players at a time. IDs/slugs are comma-separated.

Example:

GET /stats/pitchers?ids=j3k8e,max-scherzer,gerrit-cole

Support

Please contact us with any issues you are having by emailing us at support@moonlabs.app. If there is a feature you’d like us to add, please let us know!