NHLGames

NHLGames datasource lets you create subscriptions for the next NHL games and results. With Hooks Query Language you can customize what data and when you want to receive:

InputOutputCreditsFreshness
NHLGame1 minute

What you can get from this API

  • Get an update when a team starts or ends a game with a score and other NHLGame data.
  • Get an update when a team wins a game or ends a game with a score.
  • Get all the games for an NHL team.

How to Use

As every datasource at Hooks, you can choose to pull the data in your preferred format or to set up a webhook to receive the data when something happens.  

As we offer many datasources, we have developed a custom SQL-Like language (Hooks Query Language) to be able to query each datasource in the same format. To create a subscription the first thing you need to do is to define an HQL query and then send this query to create subscription endpoint.

NHLGames datasource has no mandatory parameters and you can use an optional WHERE clause to filter the output data (NHLGame) in order to receive just what you need. Hooks will then call your webhook once new data is available for your query. 

 

 

Step 1: Customize subscription

 

Hooks provide an elegant mechanism for creating subscriptions using Hooks Query Language. It has a similar notation to SQL and lets you define each subscription with a simple HQL query.

The following query will create a subscription to “Send me updates for all New Jersey Devils games 1 hour before the start”:

SELECT * FROM NHLGames
WHERE status='FUTURE'
AND (away_team.team_name='New Jersey Devils'
OR home_team.team_name='New Jersey Devils')
AND start_datetime.countdown = 3600

Once this HQL query has new results – 1-hour before New Jersey Devils plays a new game – Hooks will send NHLGame object to your webhook:

{
    "matches_count": 1,
    "results": [
        {
            "_entity_type": "NHLGame",
            "_id": "NHLGame_400962534",
            "away_score": null,
            "away_team": {
                "_entity_type": "NHLTeam",
                "_id": "NHLTeam_NJ",
                "acronym": "NJ",
                "division": "Metropolitan Division",
                "id": "NHLTeam_NJ",
                "team_name": "New Jersey Devils"
            },
            "game_id": "400962534",
            "home_team": {
                "_entity_type": "NHLTeam",
                "_id": null,
                "acronym": null
            },
            "link": "http://espn.go.com/nhl/gamecast?gameId=400962534",
            "start_datetime": {
                "countdown": 134517,
                "datetime": "2018-02-23T00:00:00+0000",
                "timestamp": 1519344000
            },
            "status": "FUTURE"
        }
    ]
}

Please take a look at the above object. You can use WHERE clause to filter all the properties of NHLGame object and only get updates for what you need. 

Optional: Pull the data

You can use fetch endpoint to request the data currently available for your HQL query. Hooks will return the latest data available for HQL query. The result may be empty if we currently don’t have any data available for your query. NHLGames datasource has data for today, tomorrow and yesterday games.

To pull the data for “All New Jersey Devils soccer games” you can use.

SELECT * FROM NHLGames 
WHERE status='FUTURE'
AND (away_team.team_name='New Jersey Devils'
OR home_team.team_name='New Jersey Devils')

This query will return all soccer games planned for yesterday, today and tomorrow:

{
    "matches_count": 1,
    "results": [
        {
            "_entity_type": "NHLGame",
            "_id": "NHLGame_400962534",
            "away_score": null,
            "away_team": {
                "_entity_type": "NHLTeam",
                "_id": "NHLTeam_NJ",
                "acronym": "NJ",
                "division": "Metropolitan Division",
                "id": "NHLTeam_NJ",
                "team_name": "New Jersey Devils"
            },
            "game_id": "400962534",
            "home_team": {
                "_entity_type": "NHLTeam",
                "_id": null,
                "acronym": null
            },
            "link": "http://espn.go.com/nhl/gamecast?gameId=400962534",
            "start_datetime": {
                "countdown": 134078,
                "datetime": "2018-02-23T00:00:00+0000",
                "timestamp": 1519344000
            },
            "status": "FUTURE"
        }
    ]
}

Step 2: Create subscription

 

To create a subscription you just need to send an HQL query and a title of your choice to subscriptions endpoint:

curl -H "Content-type: application/json" -d '{
	"query": "SELECT * FROM NHLGames WHERE status=\'FUTURE\' and (away_team.team_name=\'New Jersey Devils\' or home_team.team_name=\'New Jersey Devils\') and start_datetime.countdown <= 3600"
}' 'http://api.hooksdata.io/v1/subscriptions'

Hooks will then create a subscription on our servers and call your webhook once new data is available for your query.

 

Examples

Using HQL you can customize what data you want to select from a datasource and also filter the output using a WHERE clause. The following examples show how you can use HQL to choose just the data you need:

New Jersey Devils are going to play a game in 1 hour.

SELECT * FROM NHLGames
WHERE status='FUTURE'
AND (away_team.team_name = 'New Jersey Devils'
OR home_team.team_name = 'New Jersey Devils')
AND start_datetime.countdown = 3600

 

New Jersey Devils won Columbus Blue Jackets with a score 2:1.

 

SELECT * FROM NHLGames WHERE
status = 'FINISHED'
AND away_team.team_name = 'Columbus Blue Jackets'
AND home_team.team_name='New Jersey Devils'
AND home_score = 2 
AND away_score = 1

 

NHL game ended with a score 2:1 or 1:2.

SELECT * FROM NHLGames 
WHERE status = 'FINISHED'
AND (away_score = 2
AND home_score = 1) OR (home_score = 2
AND away_score = 1)