Overview
The API Playground is an interactive tool for exploring MLB’s Stats API. Test endpoints, view responses, and understand the data structure without writing code.Getting Started
Access the API Playground from the main navigation:API Versions
MLB provides multiple API versions:- v1.1 (Recommended)
- v1.0
Latest stable version with:
- Enhanced field filtering
- Improved performance
- Extended data coverage
- Better documentation
Endpoint Categories
API endpoints are organized by data type:Schedule Endpoints
/api/v1/schedule
Get games by date range, team, or season.
/api/v1.1/schedule
Enhanced scheduling with flexible date parameters.
Game Endpoints
/api/v1.1/game/{gamePk}/feed/live
Live game data with play-by-play.
/api/v1/game/{gamePk}/boxscore
Detailed box score statistics.
/api/v1/game/{gamePk}/linescore
Inning-by-inning scoring summary.
/api/v1/game/{gamePk}/winProbability
Play-by-play win probability data.
Player Endpoints
/api/v1/people/{personId}
Individual player information and stats.
/api/v1/people/search
Search for players by name.
Team Endpoints
/api/v1/teams
List of all MLB teams.
/api/v1/teams/{teamId}/roster
Current team roster.
Standings Endpoints
/api/v1/standings
League and division standings with customizable parameters.
Query Parameters
Most endpoints accept parameters to filter and customize responses:Common Parameters
sportId
sportId
Filter by sport:
1= MLB (default)- Other values for minor leagues
season
season
Specify season year:
2024,2023, etc.- Defaults to current season
gameType
gameType
Filter by game type:
R= Regular SeasonS= Spring TrainingF= Wild CardD= Division SeriesL= League ChampionshipW= World Series
hydrate
hydrate
Include additional data:
hydrate=team- Include team detailshydrate=linescore- Add linescorehydrate=decisions- Include pitching decisions- Multiple values comma-separated
fields
fields
Select specific response fields:
- Reduces payload size
- Improves performance
- Comma-separated list
- Example:
fields=teams,away,home,name,id
Making Requests
The playground interface provides:Request Builder
Response Viewer
After executing a request:- JSON Response: Formatted and syntax-highlighted
- Status Code: HTTP response code (200, 404, etc.)
- Response Time: How long the request took
- Headers: Response headers from the API
- Copy Button: Copy JSON to clipboard
- Download: Save response as a file
Example Use Cases
Get Today’s Games
Live Game Data
Player Stats
Team Standings
Field Filtering
Reduce response size by requesting specific fields:Hydration Options
Enrich responses with related data:Available Hydrations
team- Team detailslinescore- Inning-by-inning scoresflags- Game flags (no-hitter, perfect game)scoringplays- All plays that scored runsdecisions- Winning/losing/saving pitcherperson- Player biographical infostats- Statistical datacurrentTeam- Player’s current team
Multiple Hydrations
More hydrations = larger response size. Only request what you need.
Rate Limiting
The MLB Stats API has rate limits:- Limits vary by endpoint
- Excessive requests may be throttled
- Use field filtering to reduce calls
- Cache responses when possible
- The playground enforces reasonable limits
Error Handling
Common error responses:404 Not Found
404 Not Found
The requested resource doesn’t exist:
- Invalid game ID
- Player not found
- Wrong endpoint path
400 Bad Request
400 Bad Request
Invalid parameters:
- Missing required parameter
- Invalid date format
- Malformed field filter
500 Server Error
500 Server Error
API server issue:
- Try again later
- Check MLB API status
- Report persistent errors
Best Practices
Use Field Filtering
Request only needed fields to improve performance and reduce bandwidth.
Cache Responses
Store responses for historical data that won’t change.
Handle Errors
Check status codes and handle errors gracefully in your application.
Respect Limits
Don’t exceed rate limits; implement backoff strategies.
Integration Examples
The playground helps you understand the API before integrating it into your app:- Test Endpoints: Verify the data structure
- Copy Requests: Use the generated URLs in your code
- Understand Responses: Know what fields are available
- Debug Issues: Test parameters and troubleshoot errors
Related: API Overview
View complete API documentation and endpoint reference.
Saving Requests
Future feature: Save frequently used requests for quick access later.
Sharing Playground Links
Future feature: Share playground configurations via URL parameters.
Back to Features
Explore other core features of MLB.TheOhtani.com.