High-level team APIs

The high-level team APIs intend to provide convenient functionality used by most users. Each function from the teams API returns a data frame with the requested data processed to serve common purposes.

Note that while some of the showcased examples use the dplyr package to manipulate the data, the nhlapi package itself does not import it and the user is free to use whichever methods to manipulate the data.


Team information

# Get meta information on all teams

Current rosters

# Get current rosters for all teams
rosters <- nhl_teams_rosters()

# View the current roster for the Devils
roster_devils <- rosters %>%
  filter(name == "New Jersey Devils") %>%
  pull(roster.roster) %>%
  # This is still a list, extract the first element

Rosters for past seasons

# Get rosters for a specific season, all teams
rosters_1993 <- nhl_teams_rosters(seasons = 1993)

# Select the Quebec Nordiques
roster_nordiques_1993 <- rosters_1993 %>%
  filter(name == "Quebec Nordiques") %>%

Multiple seasons rosters

# Works with multiple seasons
rosters_1993_1994 <- nhl_teams_rosters(
  seasons = c(1993:1995)

# It is a bit nicer though (for traffic) to get less data
# and make more specific requests - e.g. only get the Nordiques
rosters_1993_1994 <- nhl_teams_rosters(
  teamIds = 32,
  seasons = c(1993:1995)

Upcoming and previous games

Details on previous game for teams

# Previous game for all teams

# Previous game for selected teams

Exploring the full game details

There is a lot of information about games in the API, for instance, full details of the previous of the Devils:

# First get the API URL for the relevant game
game_url <- nhl_teams_shedule_previous(1) %>%
  extract2("previousGameSchedule.dates") %>% first() %>%
  extract2("games") %>% first() %>%

# Now use `nhl_get_data()` to retrieve the data
game_data <- file.path("https://statsapi.web.nhl.com", game_url) %>%

# This is a very complex nested endpoint, for instance,
# look at the recorded events in the game
game_plays <- game_data %>% first() %>%
  extract2("liveData") %>%
  extract2("plays") %>%
  extract2("allPlays") %>%


Details on upcoming game for teams

# Next game for all teams

# Next game for selected teams

Team Stats per season

# All teams, current season
# Selected teams, selected seasons
nhl_teams_stats(1, 2005:2006)

Investigate the returned object

# Get 2 seasons for the Devils:
devils_stats <- nhl_teams_stats(1, 2005:2006)

# Look at the teamStats object for the first of them
# Requires `dplyr` attached using library
devils_stats %>%
  extract2("teamStats") %>% first() %>%
  extract2("splits") %>% first() %>%
  slice(1) %>%
  select(stat.gamesPlayed, stat.wins, stat.losses)