dword4 / nhlapi

Documenting the publicly accessible portions of the NHL API
448 stars 56 forks source link

statsapi.web.nhl.com appears to be gone #29

Closed wrinkledcheese closed 9 months ago

wrinkledcheese commented 10 months ago

Of course it disappears after I figure out https://statsapi.web.nhl.com/api/v1/schedule/?expand=schedule.teams,team.roster,team.stats,roster.person,person.stats&stats=statsSingleSeason&season=20232024&date=2023-11-04 will fetch an entire day's schedule, teams schedule to play, stats for those teams, rosters for those teams and stats for the players in the roster. The expands can be chained so long as they're relevant to the data as expanded. I wasn't sure if order mattered. If you excluded date it would download the entire schedule for the entire year which was about 100MB - woops.

The resulting data would be: https://pastebin.com/CQe2tP8Z

Will have to use nhle, I guess. I just hate it has a hard limit of 100 items, which reflects their own site's maximum items limit. Breaking requests up into 100s can be problematic. You also can't dictate which data to fetch as you could with the expands, however, you still have control over the "WHERE" clause with the Apache Cayenne Expression.

reaganking commented 10 months ago

Same issue here. Just finished building a simple standings page with some added calcs in the table. What's the other option you listed @wrinkledcheese ? nhle?

bags6439 commented 10 months ago

I just found it and was trying to learn how to pull in data into Excel. I thought I was doing something wrong when it wouldn't work today.

Andriamanitra commented 10 months ago

Will have to use nhle, I guess.

What's nhle? I'm still hoping statsapi.web.nhl.com is not permanently down because I had built a nice website for myself on top of it, but I should probably start looking for alternative data sources. :disappointed:

wrinkledcheese commented 10 months ago

statsapi.web.nhl.com was what they used in the old website. I probably set off some DDoS alarms on their system by accidentally sending 2 requests for 100MB of data each. If you exclude the date in the link above, it fetches the schedule for the year. every team playing for every day ( duplicates of team, team stats, and player stats for every day ). I did that on Nov 4th. I would think it's quite the coincidence if they shut it down 3 days later. nhle.com is their new API on the NHL.com API. There was initial docs for it somewhere by d4word. Whereas I'm using it for my own purposes and by nowhere near exhausting the APIs abilities, I will not be documenting it. Should be easy enough to reverse engineer the bits you need from nhl.com with Chrome developer tools on the network tab. Just look for the JSON data. Keep an eye out for responses that say "there was no data that can be displayed as it was redirected". The only thing that sucks is the old statsapi.web.nhl.com API had rosterStatus to denote injured players and I have not been able to find that on the new API.

Basically just look for network requests from the new API. I think it's api-web.nhle.com. Actually it looks like some requests are from api.nhle.com as well. May have to pay attention to the subdomain.

The reason I think it's down for good is they had 2 requests for just over 100MB of data from me. Take a modest 5,000 botnet and that's 500GB of data per request as fast as the botnet can send them. Pretty sure that would set records.

I am equally disappointed as nhle.com only allows maximum 100 items per request, and with 30 teams with ~30 players per team, you can easily have to request 900 skaters in a single day for the stats updated from the game they had played previously.

I was keeping the stackable expand field to myself as "trade secret" until now. I'm fairly certain the old API is down for good due to it's potential to be used for DDoS.

wrinkledcheese commented 10 months ago

I just found it and was trying to learn how to pull in data into Excel. I thought I was doing something wrong when it wouldn't work today.

Just dump it into CSV and excel ( Libre/Open Office calc ) can import CSV. You can even make the first row of the CSV the names of the columns.

DankTechnologies commented 10 months ago

If you're just interested in the recent schedule + scores, the duckduckgo API is a decent substitute.

https://duckduckgo.com/sports.js?q=nhl&league=nhl&type=games&o=json

They have nice SVG logos for all of the teams as well.

bags6439 commented 10 months ago

We are playing “Light the lamp” and I am working with my daughter to pull in the games and award the points for each LTL player based on which Red Wing player they picked that game. On Nov 7, 2023, at 7:45 PM, wrinkledcheese @.***> wrote:

I just found it and was trying to learn how to pull in data into Excel. I thought I was doing something wrong when it wouldn't work today.

Just dump it into CSV and excel and import CSV.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

luminatee commented 10 months ago

Very sad. And what should I do now? Is it worth waiting for a recovery? Or can you suggest an analogue with a similar structure to make minimal changes in the code? Thank you.

DevAxia commented 10 months ago

Anybody has found a way to figure out the endpoints for the replacement https://api-web.nhle.com/ ?

luminatee commented 10 months ago

statsapi.web.nhl.com was what they used in the old website. I probably set off some DDoS alarms on their system by accidentally sending 2 requests for 100MB of data each. If you exclude the date in the link above, it fetches the schedule for the year. every team playing for every day ( duplicates of team, team stats, and player stats for every day ). I did that on Nov 4th. I would think it's quite the coincidence if they shut it down 3 days later. nhle.com is their new API on the NHL.com API. There was initial docs for it somewhere by d4word. Whereas I'm using it for my own purposes and by nowhere near exhausting the APIs abilities, I will not be documenting it. Should be easy enough to reverse engineer the bits you need from nhl.com with Chrome developer tools on the network tab. Just look for the JSON data. Keep an eye out for responses that say "there was no data that can be displayed as it was redirected". The only thing that sucks is the old statsapi.web.nhl.com API had rosterStatus to denote injured players and I have not been able to find that on the new API.

Basically just look for network requests from the new API. I think it's api-web.nhle.com. Actually it looks like some requests are from api.nhle.com as well. May have to pay attention to the subdomain.

The reason I think it's down for good is they had 2 requests for just over 100MB of data from me. Take a modest 5,000 botnet and that's 500GB of data per request as fast as the botnet can send them. Pretty sure that would set records.

I am equally disappointed as nhle.com only allows maximum 100 items per request, and with 30 teams with ~30 players per team, you can easily have to request 900 skaters in a single day for the stats updated from the game they had played previously.

I was keeping the stackable expand field to myself as "trade secret" until now. I'm fairly certain the old API is down for good due to it's potential to be used for DDoS.

api.nhle.com and api-web.nhle.com do not work with direct links. How can they be used?

luminatee commented 10 months ago

If you're just interested in the recent schedule + scores, the duckduckgo API is a decent substitute.

https://duckduckgo.com/sports.js?q=nhl&league=nhl&type=games&o=json

They have nice SVG logos for all of the teams as well.

Thank you for the link. Is there any documentation available for it? Do the match data display in real time?

Wayne-II commented 10 months ago

If you're just interested in the recent schedule + scores, the duckduckgo API is a decent substitute. https://duckduckgo.com/sports.js?q=nhl&league=nhl&type=games&o=json They have nice SVG logos for all of the teams as well.

Thank you for the link. Is there any documentation available for it? Do the match data display in real time?

Highly unlikely, NHL requires that any live stats must not be updated more than 3 times per period unless it's an officially licensed NHL stream.

jayParent commented 10 months ago

The reason I think it's down for good is they had 2 requests for just over 100MB of data from me. Take a modest 5,000 botnet and that's 500GB of data per request as fast as the botnet can send them. Pretty sure that would set records.

I started using this API around the same time as you and spammed it quite a bit myself. I also thought it may have been my fault... thanks for the info.

wrinkledcheese commented 10 months ago

api.nhle.com and api-web.nhle.com do not work with direct links. How can they be used?

In Google Chrome: 1) With a page at NHL.com loaded with the data you want, on the right hand side click the three dots. 2) Hover over the option "More Tools" 3) Select "Developer Tools" 4) select the "Network Tab" at the top. 5) Refresh the page 6) go through all the network requests to find the data you're looking for. In particular look for requests to the domains mentioned in earlier comments.

Eg on the main page of NHL.com, in the Dev Tools Network Tab, you will see a lot of entries. There's one for https://geolocation.onetrust.com/cookieconsentpub/v1/geo/location but it only shows the last entry in the "path". So "location". This is a 3rd party API NHL uses to find out where people are from that uses their website. The response is {"country":"XX","state":"XX","stateName":"Some State","continent":"XX"}. To get the URL just right click location, hover over copy, and click copy link address. Pay attention to the parameters in the query. In this case there are none.

If you keep scrolling through the items in the network tab in the section with the title "Name" you will come across one that says "now". The link is https://api-web.nhle.com/v1/scoreboard/now. This will give you the current schedule for what seems to be 7 days. It starts on the 4th of Nov and goes for 7 days, inclusive. Processing this data will allow you to get what you need. Intermixing your logic ( what to do with data ) and your models ( data descriptions/API response format ) is bad mojo and results in code that is hard to maintain, or adapt to new data structures. It's common for beginners though. A "model" is just ab object that identically matches the JSON response format if you're getting JSON, which allows you to write code that will convert a string of JSON to an Object instance, representing your model. That way you can do skater.goals instead of skater[ 'goals' ]. This also allows you to use ORM ( database abstraction libraries - Object relational mapping - mapping between code objects and a relational database ) to store your data locally. Not sure what language you guys are using but I use Flask-restx, and sqlalchemy for python for my API and database libraries. Keep lookig and find the data that you want. The data is usually in the response tab. It will likely say sommething like "Failed to load response data: No content available because this request was redirected. If you copy and past the link into your browser, you will get the data.

This works for any website/API. The caveat is that some websites require authentication, which is usually done through an API key. But that's "...just slavery with extra steps." -- Morty

Give a man a fish, and you fed him for a day. Teach a man to fish, and you've fed him for a lifetime.

If you do some Googling, d4word has a gitlabs with the newer API starting to be documented, I can't find it though. Just Google NHL API and look for one that says GitLabs and d4word in the URL.

wrinkledcheese commented 10 months ago

I started using this API around the same time as you and spammed it quite a bit myself. I also thought it may have been my fault... thanks for the info.

I used to send hundreds of requests without issues. I started using this API about 2 or 3 years ago. I don't think the request count mattered a whole lot. What's a big concern in DDoS is resources ( eg connections[ports], or bandwidth ) per request. In this case, bandwidth was likely the issue. Being able to easily get 100MB in seconds from a single request is a bad thing if you're concerned about DDoS.

bags6439 commented 10 months ago

I wanted to say thanks, I used Google to trace the NHLE calls from nhl.com and found the roster, schedule and gamestats to make my api calls.

Joe

From: wrinkledcheese @.> Sent: Tuesday, November 7, 2023 6:47 PM To: dword4/nhlapi @.> Cc: bags6439 @.>; Comment @.> Subject: Re: [dword4/nhlapi] statsapi.web.nhl.com appears to be gone (Issue #29)

statsapi.web.nhl.com was what they used in the old website. I probably set off some DDoS alarms on their system by accidentally sending 2 requests for 100MB of data each. If you exclude the date in the link above, it fetches the schedule for the year. every team playing for every day ( duplicates of team, team stats, and player stats for every day ). I did that on Nov 4th. I would think it's quite the coincidence if they shut it down 3 days later. nhle.com is their new API on the NHL.com API. There was initial docs for it somewhere by d4word. Whereas I'm using it for my own purposes and by nowhere near exhausting the APIs abilities, I will not be documenting it. Should be easy enough to reverse engineer the bits you need from nhl.com with Chrome developer tools on the network tab. Just look for the JSON data. Keep an eye out for responses that say "there was no data that can be displayed as it was redirected". The only thing that sucks is the old statsapi.web.nhl.com API had rosterStatus to denote injured players and I have not been able to find that on the new API.

— Reply to this email directly, view it on GitHub https://github.com/dword4/nhlapi/issues/29#issuecomment-1800800723 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AITRNYP6YE5BKY2Z2S4TSXTYDLJARAVCNFSM6AAAAAA7BZKHPKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBQHAYDANZSGM . You are receiving this because you commented. https://github.com/notifications/beacon/AITRNYNDISPOGQBVU2NW4ULYDLJARA5CNFSM6AAAAAA7BZKHPKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTLKYE5G.gif Message ID: @. @.> >

luminatee commented 9 months ago

api.nhle.com и api-web.nhle.com не работают с прямыми ссылками. Как их можно использовать?

В Google Chrome: 1) На странице по адресу NHL.com загружены нужные данные, с правой стороны нажмите на три точки. 2) Наведите курсор мыши на опцию "Дополнительные инструменты" 3) Выберите "Инструменты разработчика" 4) выберите "Сетевую вкладку" вверху. 5) Обновите страницу 6) просмотрите все сетевые запросы, чтобы найти нужные данные. В частности, ищите запросы к доменам, упомянутым в предыдущих комментариях.

Например, на главной странице NHL.com, на вкладке Dev Tools Network, вы увидите много записей. Есть один для https://geolocation.onetrust.com/cookieconsentpub/v1/geo/location но он показывает только последнюю запись в "пути". Итак, "местоположение". Это сторонний API, который использует NHL, чтобы узнать, откуда люди, которые используют их веб-сайт. Ответ таков {"country":"XX","state":"XX","StateName":"Some State","continent":"XX"}. Чтобы получить URL-адрес, просто щелкните правой кнопкой мыши местоположение, наведите курсор мыши на копировать и выберите копировать адрес ссылки. Обратите внимание на параметры в запросе. В данном случае их нет.

Если вы продолжите прокручивать элементы на вкладке "Сеть" в разделе с заголовком "Имя", вы наткнетесь на тот, на котором написано "сейчас". Ссылка есть https://api-web.nhle.com/v1/scoreboard/now. Это даст вам текущее расписание на период, который, по-видимому, составляет 7 дней. Оно начинается 4 ноября и длится 7 дней включительно. Обработка этих данных позволит вам получить то, что вам нужно. Смешивание вашей логики (что делать с данными) и ваших моделей ( описания данных / формат ответа API) является плохим моджо и приводит к созданию кода, который трудно поддерживать или адаптировать к новым структурам данных. Хотя для новичков это обычное дело. "Модель" - это просто объект ab, который идентично соответствует формату ответа JSON, если вы получаете JSON, что позволяет вам написать код, который преобразует строку JSON в экземпляр объекта, представляющий вашу модель. Таким образом, вы можете использовать skater.goals вместо skater[ 'цели']. Это также позволяет вам использовать ORM ( библиотеки абстракции базы данных - Объектно-реляционное сопоставление - сопоставление между объектами кода и реляционной базой данных) для локального хранения ваших данных. Не уверен, какой язык вы, ребята, используете, но я использую Flask-restx и sqlalchemy для python для моего API и библиотек баз данных. Продолжайте искать и найдите нужные данные. Данные обычно находятся на вкладке ответа. Скорее всего, в нем будет написано что-то вроде "Не удалось загрузить данные ответа: содержимое недоступно, поскольку этот запрос был перенаправлен. Если вы скопируете ссылку и вставите ее в свой браузер, вы получите данные.

Это работает для любого веб-сайта / API. Нюанс в том, что некоторые веб-сайты требуют аутентификации, которая обычно выполняется с помощью ключа API. Но это "...просто рабство с дополнительными шагами". -- Морти

Дайте мужчине рыбу, и вы накормите его на день. Научите мужчину ловить рыбу, и вы накормите его на всю жизнь.

Если вы немного погуглите, у d4word есть gitlabs с новым API, который начинает документироваться, я не могу его найти. Просто загуглите NHL API и найдите тот, в URL-адресе которого указаны GitLabs и d4word.

Please provide information about the possible values and their meanings for the "gameType" parameter in the API https://api-web.nhle.com/v1/scoreboard/now.

luminatee commented 9 months ago

@wrinkledcheese Those values in the API https://api-web.nhle.com/v1/schedule/2023-11-14 are: gameState == ['status']['detailedState'] (old API) gameScheduleState == ['status']['statusCode'] (old API) Am I correct? Can you share the breakdown of all the values for gameState and gameScheduleState?

wrinkledcheese commented 9 months ago

@wrinkledcheese Those values in the API https://api-web.nhle.com/v1/schedule/2023-11-14 are: gameState == ['status']['detailedState'] (old API) gameScheduleState == ['status']['statusCode'] (old API) Am I correct? Can you share the breakdown of all the values for gameState and gameScheduleState?

Check the readme in the root of this github repo.

bags6439 commented 9 months ago

As I can’t read or speak Russian and since this is about hockey I will respond and say:“Pavel Datsuk!”Enough said.  LGRWOn Nov 20, 2023, at 2:41 PM, luminatee @.***> wrote:

api.nhle.com и api-web.nhle.com не работают с прямыми ссылками. Как их можно использовать?

В Google Chrome: 1) На странице по адресу NHL.com загружены нужные данные, с правой стороны нажмите на три точки. 2) Наведите курсор мыши на опцию "Дополнительные инструменты" 3) Выберите "Инструменты разработчика" 4) выберите "Сетевую вкладку" вверху. 5) Обновите страницу 6) просмотрите все сетевые запросы, чтобы найти нужные данные. В частности, ищите запросы к доменам, упомянутым в предыдущих комментариях. Например, на главной странице NHL.com, на вкладке Dev Tools Network, вы увидите много записей. Есть один для https://geolocation.onetrust.com/cookieconsentpub/v1/geo/location но он показывает только последнюю запись в "пути". Итак, "местоположение". Это сторонний API, который использует NHL, чтобы узнать, откуда люди, которые используют их веб-сайт. Ответ таков {"country":"XX","state":"XX","StateName":"Some State","continent":"XX"}. Чтобы получить URL-адрес, просто щелкните правой кнопкой мыши местоположение, наведите курсор мыши на копировать и выберите копировать адрес ссылки. Обратите внимание на параметры в запросе. В данном случае их нет. Если вы продолжите прокручивать элементы на вкладке "Сеть" в разделе с заголовком "Имя", вы наткнетесь на тот, на котором написано "сейчас". Ссылка есть https://api-web.nhle.com/v1/scoreboard/now. Это даст вам текущее расписание на период, который, по-видимому, составляет 7 дней. Оно начинается 4 ноября и длится 7 дней включительно. Обработка этих данных позволит вам получить то, что вам нужно. Смешивание вашей логики (что делать с данными) и ваших моделей ( описания данных / формат ответа API) является плохим моджо и приводит к созданию кода, который трудно поддерживать или адаптировать к новым структурам данных. Хотя для новичков это обычное дело. "Модель" - это просто объект ab, который идентично соответствует формату ответа JSON, если вы получаете JSON, что позволяет вам написать код, который преобразует строку JSON в экземпляр объекта, представляющий вашу модель. Таким образом, вы можете использовать skater.goals вместо skater[ 'цели']. Это также позволяет вам использовать ORM ( библиотеки абстракции базы данных - Объектно-реляционное сопоставление - сопоставление между объектами кода и реляционной базой данных) для локального хранения ваших данных. Не уверен, какой язык вы, ребята, используете, но я использую Flask-restx и sqlalchemy для python для моего API и библиотек баз данных. Продолжайте искать и найдите нужные данные. Данные обычно находятся на вкладке ответа. Скорее всего, в нем будет написано что-то вроде "Не удалось загрузить данные ответа: содержимое недоступно, поскольку этот запрос был перенаправлен. Если вы скопируете ссылку и вставите ее в свой браузер, вы получите данные. Это работает для любого веб-сайта / API. Нюанс в том, что некоторые веб-сайты требуют аутентификации, которая обычно выполняется с помощью ключа API. Но это "...просто рабство с дополнительными шагами". -- Морти Дайте мужчине рыбу, и вы накормите его на день. Научите мужчину ловить рыбу, и вы накормите его на всю жизнь. Если вы немного погуглите, у d4word есть gitlabs с новым API, который начинает документироваться, я не могу его найти. Просто загуглите NHL API и найдите тот, в URL-адресе которого указаны GitLabs и d4word.

Please provide information about the possible values and their meanings for the "gameType" parameter in the API https://api-web.nhle.com/v1/scoreboard/now.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

wrinkledcheese commented 9 months ago

As I can’t read or speak Russian and since this is about hockey I will respond and say:“Pavel Datsuk!”Enough said.  LGRW

The Russian was quoted, so his email client or browser translated my post to Russian. His question was English asking for more information regarding the new API. I directed him to the new home for this documentation on d4word's gitlab via this repo's Readme file.