MLB.com’s unofficially, thoroughly awesome API

So MLB.come has an unofficial API. When you go to any player’s page and open up an inspector such as Firefox’s Firebug or Safari’s Web Inspector, you can see that the page initiates a bunch of AJAX requests for various information including awesomely useful information such as player statistics and game logs.

Behold Felix Hernandez’s ‘core’ player information. Mouse-over to see the URL.

And then you can get Felix’s game log using this incredibly long URL. I haven’t really played with the query string parameters too much, but there’s one, ‘results’, which is used on the player’s page to limit the number of games shown to 10. Making that 165 will show all for the season. Likewise there’s ‘year’ which corresponds to the season. I’m not quite sure how far back the data will go. There’s also a ‘game_type’, which given that the value used in the URLs in this post is ‘R’, means regular/post/preseason.

Here’s the URL for a position player, Ichiro’s 2009 stats.

There are more GET calls to return detailed player biography and news-related items, awards, and other stuff. There are also GET calls on the team pages for team information.

Anyway. I’m pretty certain that these APIs are not meant for public consumption, and could change at any time, though I hope not, because they are awesome. You can use the data returned with any basic knowledge of XML and JSON, and most (if not all) programming languages now have pretty solid libraries for that.

Update: I have made a python abstraction layer for the MLB.com API. You can find it on its github project page or read more about it on this blog post.

FINAL UPDATE – This project lives now on my baseball projects page.

Leave a comment

RSS feed for comments on this post