Skip to contents

Find game_pk values for professional baseball games (major and minor leagues) via the MLB api https://www.mlb.com/

Usage

mlb_game_pks(date, level_ids = c(1))

Arguments

date

The date for which you want to find game_pk values for MLB games

level_ids

A numeric vector with ids for each level where game_pks are desired. See below for a reference of level ids.

Value

Returns a tibble that includes game_pk values and additional information for games scheduled or played with the following columns:

col_nametypesdescription
game_pkintegerUnique game identifier.
gameGuidcharacterGlobally unique game identifier.
linkcharacterMLB Stats API relative game link.
gameTypecharacterGame type code (R, P, etc.).
seasoncharacterSeason (YYYY).
gameDatecharacterGame date-time (ISO 8601, UTC).
officialDatecharacterOfficial game date (YYYY-MM-DD).
isTielogicalWhether the game ended in a tie.
gameNumberintegerGame number within a doubleheader.
publicFacinglogicalWhether the game is public-facing.
doubleHeadercharacterDoubleheader indicator (N/Y/S).
gamedayTypecharacterGameday data type code.
tiebreakercharacterTiebreaker indicator.
calendarEventIDcharacterCalendar event identifier.
seasonDisplaycharacterDisplay season (YYYY).
dayNightcharacterDay/night designation.
scheduledInningsintegerNumber of scheduled innings.
reverseHomeAwayStatuslogicalWhether home/away designation is reversed.
inningBreakLengthintegerLength of the inning break (seconds).
gamesInSeriesintegerTotal games in the series.
seriesGameNumberintegerGame number within the series.
seriesDescriptioncharacterSeries description.
recordSourcecharacterSource of the record data.
ifNecessarycharacterWhether the game is played only if necessary.
ifNecessaryDescriptioncharacterIf-necessary description.
status.abstractGameStatecharacterAbstract game state (e.g. Final).
status.codedGameStatecharacterCoded game state.
status.detailedStatecharacterDetailed game state.
status.statusCodecharacterGame status code.
status.startTimeTBDlogicalWhether the start time is TBD.
status.abstractGameCodecharacterAbstract game code.
teams.away.scoreintegerAway team score.
teams.away.isWinnerlogicalWhether the away team won.
teams.away.splitSquadlogicalWhether the away team is a split squad.
teams.away.seriesNumberintegerAway team series number.
teams.away.team.idintegerAway team MLB ID.
teams.away.team.namecharacterAway team name.
teams.away.team.linkcharacterMLB Stats API relative away team link.
teams.away.leagueRecord.winsintegerAway team league-record wins.
teams.away.leagueRecord.lossesintegerAway team league-record losses.
teams.away.leagueRecord.tiesintegerAway team league-record ties.
teams.away.leagueRecord.pctcharacterAway team winning percentage.
teams.home.scoreintegerHome team score.
teams.home.isWinnerlogicalWhether the home team won.
teams.home.splitSquadlogicalWhether the home team is a split squad.
teams.home.seriesNumberintegerHome team series number.
teams.home.team.idintegerHome team MLB ID.
teams.home.team.namecharacterHome team name.
teams.home.team.linkcharacterMLB Stats API relative home team link.
teams.home.leagueRecord.winsintegerHome team league-record wins.
teams.home.leagueRecord.lossesintegerHome team league-record losses.
teams.home.leagueRecord.tiesintegerHome team league-record ties.
teams.home.leagueRecord.pctcharacterHome team winning percentage.
venue.idintegerVenue ID.
venue.namecharacterVenue name.
venue.linkcharacterMLB Stats API relative venue link.
content.linkcharacterMLB Stats API relative game content link.

Details

Level IDs:

The following IDs can be passed to the level_ids argument:

1 = MLB 11 = Triple-A 12 = Doubl-A 13 = Class A Advanced 14 = Class A 15 = Class A Short Season 5442 = Rookie Advanced 16 = Rookie 17 = Winter League

Examples

# \donttest{
  try(mlb_game_pks("2019-04-29"))
#> ── MLB Game Pks data from MLB.com ─────────────────── baseballr 2.0.0 ──
#>  Data updated: 2026-06-12 14:09:33 UTC
#> # A tibble: 9 × 57
#>   game_pk gameGuid     link  gameType season gameDate officialDate isTie
#>     <int> <chr>        <chr> <chr>    <chr>  <chr>    <chr>        <lgl>
#> 1  565909 f66a1949-a0… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 2  566001 204d367a-81… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 3  565040 455fea2b-f0… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 4  567173 220d5ff9-d2… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 5  566975 08410240-7e… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 6  567566 2aeee258-c3… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 7  567275 8bbe8497-80… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 8  565717 62a6f6de-55… /api… R        2019   2019-04… 2019-04-29   FALSE
#> 9  566484 0680b3a3-16… /api… R        2019   2019-04… 2019-04-29   FALSE
#> # ℹ 49 more variables: gameNumber <int>, publicFacing <lgl>,
#> #   doubleHeader <chr>, gamedayType <chr>, tiebreaker <chr>,
#> #   calendarEventID <chr>, seasonDisplay <chr>, dayNight <chr>,
#> #   scheduledInnings <int>, reverseHomeAwayStatus <lgl>,
#> #   inningBreakLength <int>, gamesInSeries <int>,
#> #   seriesGameNumber <int>, seriesDescription <chr>,
#> #   recordSource <chr>, ifNecessary <chr>, …
# }