Zmalski / NHL-API-Reference

Unofficial reference for the NHL API endpoints.
MIT License
194 stars 12 forks source link

Inconsistencies with team's roster #32

Open eric-labelle opened 1 month ago

eric-labelle commented 1 month ago

Hi, I know you don't own this API and only (did a great job) documenting it but I've been wondering if there was any API I haven't found to fetch all players?

I currently have to fetch all teams v1/roster/{team}/20242025, and then fetch each team's roster v1/player/{playerId}/landing with all the playerId found from the first call. The problem is that the roster api is often incomplete and some players are missing from teams and I can't find any way to get these missing players.

Any idea/suggestion?

Here's a few examples

Thanks

RSady commented 1 month ago

Not sure if this helps, but i'm using the/v1/roster/{teamAbbrev}/current endpoint (which will redirect to the current active season). If player doesn't show, it's likely because the NHL hasn't officially processed the player as a member of a team yet. I know when it was announced (even by the NHL) that Guentzel was traded to Tampa, he wasn't showing on their roster yet and didn't for a few days even after his contract was signed and finalized.

eric-labelle commented 1 month ago

Yes following trades I noticed it takes sometime a few days, but these players have been on their respective teams for years 🤷‍♂️

At least it's consistent with the nhl's website clearly populated by these APIs

andrewderango commented 1 month ago

Hey Eric, not sure if this is useful for you but I'll give it a shot. Once the season starts, you should be able to use the stat leaders endpoint.

https://api-web.nhle.com/v1/skater-stats-leaders/current?categories=toi&limit=9999

If you set the limit high enough you'll get every player that has played a shift in the season. However if you want players on new teams during the offseason, or players on roster that are out long term like Nichushkin or Landeskog this probably won't be the best option.

andrewderango commented 1 month ago

Another option, and probably your best bet, is to use their search API that I reverse-engineered from this page. This returns all players in their database, from players that played over a century ago and even all the 2024 draft picks!

https://search.d3.nhle.com/api/v1/search/player?culture=en-us&limit=99999&q=%2A

Obviously this is a massive call, so maybe explore some of the flags to make it more efficient such as the &active=true flag. Each player is returned as an object that contains their current team and the last season that they played. Players like Nichuskin, Reichel, and Landeskog are all listed as active players, but have their last seasons listed as 2023-24, 2023-24, and 2021-22, respectively. This explains why they aren't showing up in the teams' active rosters, because for a player to appear on team 21 (Chicago)'s active roster they must have:

  1. active=true
  2. teamId=21
  3. lastSeasonId=20242025

The only setback here is that it might be tough to differentiate between rookies that are going to play like Celebrini, Michkov and Hutson against players that are owned by NHL teams but have no chance of playing.

eric-labelle commented 4 weeks ago

Another option, and probably your best bet, is to use their search API that I reverse-engineered from this page. This returns all players in their database, from players that played over a century ago and even all the 2024 draft picks!

https://search.d3.nhle.com/api/v1/search/player?culture=en-us&limit=99999&q=%2A

Obviously this is a massive call, so maybe explore some of the flags to make it more efficient such as the &active=true flag. Each player is returned as an object that contains their current team and the last season that they played. Players like Nichuskin, Reichel, and Landeskog are all listed as active players, but have their last seasons listed as 2023-24, 2023-24, and 2021-22, respectively. This explains why they aren't showing up in the teams' active rosters, because for a player to appear on team 21 (Chicago)'s active roster they must have:

  1. active=true
  2. teamId=21
  3. lastSeasonId=20242025

The only setback here is that it might be tough to differentiate between rookies that are going to play like Celebrini, Michkov and Hutson against players that are owned by NHL teams but have no chance of playing.

Very interesting @andrewderango, thank you for that endpoint. The search doesn't seem to handle the teamId queryParam unfortunately but, I'll manage otherwise I guess.

// Should only return Chicago Blackhawks players but isn't.
curl -X GET "https://search.d3.nhle.com/api/v1/search/player?culture=en-us&teamId=16&limit=99999&q=%2A&active=true"