JavaScript
Suggested libraries to connect to the Hudl Statsbomb Live Analysis Platform using Javascript.
- node-fetch (nodejs only)
- ws (nodejs only)
- subscriptions-transport-ws
- graphql-tag
Example - Retrieving Matches
A query to return the available matches for your team within a given date
// node-fetch and util are only required for nodejs
const fetch = require('node-fetch');
const util = require('util');
const query = `query NextTeamMatch {
live_match(
where: {
_and: [
{ match_date: { _lt: "2021-10-15",
_gte: "2021-10-30" } }
{
_or: [
{ match_home_team_id: { _eq: 42 },
match_away_team_id: { _eq: 42 } }
]
}
]
}
) {
match_id
match_date
match_local_kick_off
match_name
match_home_team_id
match_away_team_id
}
}`;
fetch('<%= config[:endpoint] %>', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query
})
})
.then(r => r.json())
.then(data => console.log('data returned:', util.inspect(data, {depth: null})));
{
"NextTeamMatch": {
"live_match": [
{
"match_id": 35,
"match_date": "2020-10-09T15:00:00+00:00",
"match_local_kick_off": "15:00:00",
"match_name": "City vs United",
"match_home_team_id": 111,
"match_away_team_id": 222
},
{
"match_id": 36,
"match_date": "2020-10-09T15:00:00+00:00",
"match_local_kick_off": "15:00:00",
"match_name": "Spurs vs Liverpool",
"match_home_team_id": 673,
"match_away_team_id": 503
}
]
}
}
Retrieving competition data
Query or subscribe to all events in a particular competition, in this example competition data for the English Premier League.
// node-fetch and util are only required for nodejs
const fetch = require('node-fetch');
const util = require('util');
const query = `query CompetitionQuery {
live_competition(where: {competition_area: {area_name: {_eq: "England"}}, competition_name: {_eq: "Premier League"}}) {
competition_id
competition_name
competition_area {
area_id
area_name
}
}
}`;
fetch('<%= config[:endpoint] %>', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query
})
})
.then(r => r.json())
.then(data => console.log('data returned:', util.inspect(data, {depth: null})));