Bregman Baseball Card
In this exercise, we will get data from mlb.com API on the Houston Astro baseball player Alex Bregman.
- First, do a search on mlb.com api.
- This retrieves MLB Data API/.
Notice that this site lists endpoints such as Get Teams By Season, Get 4-Man Roster, Get Info Per Game Type.
- MLB Data API is quite helpful in showing how to set up various API requests. It shows how to get information on Yoenis Céspedes. But this project is about Alex Bregman so this is the request to enter:
%25 functions like a wildcard: for example, bregman* if you weren't sure whether his name was bregmann. %27 is the single quote character: if you replace the request string instances of %27, you see that the browser reinstates the %27.
- This of course in JSON which can be formatted at JSON Pretty Print. Paste the bregman output in it and you get this:
- Now we can start develop our Bregman Baseball Card! The initial API request provides some basic data on Alex such as birth date, height, and the all-important player ID which for Alex is 608324. The baseball card needs his performance statistics, which can be accessed with this API request:
This produces this output:
- Once again, take this output to JSON Pretty Print and get it reformatted:
- Now, there is a big Challenge: what do these abbreviations mean? https://developer.sportradar.com/docs/read/baseball/MLB_v7_with_Statcast#faqs
So now the task is to choose the rest of the data to display on thr Bregman card:
Height |
height_inches |
Height |
height_feet |
Weight |
weight |
Position |
position |
Hitting |
bats |
Throwing |
throws |
Birth date |
birth_date |
Team |
team_full |
MLB debut |
pro_debut_date |
Home runs |
hr |
RBIs |
rbi |
Average |
avg |
Slugging |
slg |
OBP |
obp |
Walks |
bb |
Hits |
h |
At bats |
ab |
Strikeouts |
so |
Doubles |
d |
Triples |
t |
At bats |
ab |
Related information
MLB.com Glossary
JSON Pretty Print
MLB Data API