MLBGames

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

Input Output Credits Freshness
MLBGame 1 minute

What you can get from this API

  • Get an update when a team starts or ends a game with a score and other MLBGame data.
  • Get an update when a team wins a game or ends a game with a score.
  • Get all the games for an MLB 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.

MLBGames datasource has no mandatory parameters and you can use an optional WHERE clause to filter the output data (MLBGame) 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 Toronto Blue Jays games 1 hour before the start”:

SELECT * FROM MLBGames
WHERE status = 'FUTURE'
AND (away_team.team_name = 'Toronto Blue Jays'
OR home_team.team_name = 'Toronto Blue Jays')
AND start_datetime.countdown = 3600


Once this HQL query has new results – 1-hour before Toronto Blue Jays play a new game – Hooks will send MLBGame object to your webhook:

{
    "matches_count": 1,
    "results": [
        {
            "_entity_type": "MLBGame",
            "_id": "MLBGame_400962533",
            "away_score": null,
            "away_team": {
                "_entity_type": "MLBTeam",
                "_id": "MLBTeam_TOR",
                "acronym": "TOR",
                "division": "AL East",
                "id": "MLBTeam_TOR",
                "team_name": "Toronto Blue Jays"
            },
            "game_id": "400962533",
            "home_team": {
                "_entity_type": "MLBTeam",
                "_id": null,
                "acronym": null
            },
            "link": "http://espn.go.com/nhl/gamecast?gameId=400962533",
            "start_datetime": {
                "countdown": 135524,
                "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 MLBGame 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. For MLBGames datasource we have data for today, yesterday and tomorrow.

To pull the data for “All Charlotte Hornets soccer games” you can use.

SELECT * FROM MLBGames 
WHERE status='FUTURE'
AND (away_team.team_name='Toronto Blue Jays'
OR home_team.team_name='Toronto Blue Jays')

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

{
    "matches_count": 1,
    "results": [
        {
            "_entity_type": "MLBGame",
            "_id": "MLBGame_400962533",
            "away_score": null,
            "away_team": {
                "_entity_type": "MLBTeam",
                "_id": "MLBTeam_TOR",
                "acronym": "TOR",
                "division": "AL East",
                "id": "MLBTeam_TOR",
                "team_name": "Toronto Blue Jays"
            },
            "game_id": "400962533",
            "home_team": {
                "_entity_type": "MLBTeam",
                "_id": null,
                "acronym": null
            },
            "link": "http://espn.go.com/nhl/gamecast?gameId=400962533",
            "start_datetime": {
                "countdown": 135524,
                "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 MLBGames WHERE status=\'FUTURE\' and (away_team.team_name=\'Toronto Blue Jays\' or home_team.team_name=\'Toronto Blue Jays\') 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:

Toronto Blue Jays is going to play a game in 1 hour.

SELECT * FROM SoccerGames 
WHERE status = 'FUTURE'
AND (away_team.team_name = 'Real Madrid'
OR home_team.team_name = 'Real Madrid')
AND start_datetime.countdown >= 3600

Toronto Blue Jays won Boston Red Sox with a score 4:6.

SELECT * FROM MLBGames WHERE
status='FINISHED'
AND away_team.team_name = 'Toronto Blue Jays'
AND home_team.team_name = 'Boston Red Sox'
AND home_score = 4
AND away_score = 6

MLB game ended with a score 4:6 or 6:4.

SELECT * FROM MLBGames 
WHERE status = 'FINISHED'
AND (away_score = 6 AND home_score = 4) OR (home_score = 6
AND away_score = 4)