•   about 1 year ago

MLB API data question

Hello - I'm running into some issues using the documentation provided by MLB for some of their API endpoints.

For example, the endpoint https://statsapi.mlb.com/api/v1/people/657077/stats?stats=season&daysBack=150&season=2024 should return statistics for this player from the last 150 days, but it's returning their full season stats. Here is the swagger JSON for the endpoint (removed some optional data for brevity):

"/api/v1/people/{personId}/stats": {
"get": {
"tags": [
"Person"
],
"summary": "View a players stats",
"operationId": "stats_3",
"parameters": [
{
"name": "personId",
"in": "path",
"description": "Unique Player Identifier. Format: 434538, 429665, etc",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "stats",
"in": "query",
"description": "Type of statistics. Format: Individual, Team, Career, etc. Available types in /api/v1/statTypes",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/StatType"
}
}
},
{
"name": "season",
"in": "query",
"description": "Season of play",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "daysBack",
"in": "query",
"description": "Returns results from the last 'X' days (Starting from yesterday).",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
},

Another simple example is the league leaders endpoint: https://statsapi.mlb.com/api/v1/stats/leaders?season=2024&statType=season

This returns no data at all. I'm not sure if I'm misunderstanding the documentation? Any help would be greatly appreciated. Thank you.

Comments are closed.