toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
533 stars 100 forks source link

Some games are hidden by the api but appear when you search by game_id with the api #82

Closed ewrwrnjwqr closed 2 years ago

ewrwrnjwqr commented 2 years ago

I can search for this specific game_id using the line of code below, but then cannot do the opposite and search by team = "American". Is there a way to get a full list of games from a day including ones hidden by the API like the game_id below. Alternatively, is there a way to return all game_id at are public-facing?

statsapi.schedule(game_id=658972)

toddrob99 commented 2 years ago

The schedule method defaults sportId to 1 for MLB. If you want games for a different league, you have to include the sportId parameter. Try statsapi.schedule(date='2019-07-09', sportId=586). List of sports available here. I got 586 from the team info for one of the teams listed in the gamePk you specified.

ewrwrnjwqr commented 2 years ago

There appears to be no data on 2022 using sportID = 586. They might've stopped posting it. Any other ideas on how I could make sure?

toddrob99 commented 2 years ago

I agree, there's nothing available for that sportId in 2022 (https://statsapi.mlb.com/api/v1/schedule?sportId=586&startDate=2022-01-01&endDate=2022-12-31). It may be posted under a different sportId for some reason. If you can view the data on an MLB website, you may be able to use your browser's developer tools to find some API calls with a gamePk or sportId you can use.