R
Suggested libraries to connect to the Hudl Statsbomb Live Analysis Platform using R:
Only Query support
GraphQL libraries for R only support queries. No subscription support known at this time
Example - Retrieving Matches
A query to return the available matches for your team within a given date
library("ghql")
library("jsonlite")
library("dplyr")
con <- GraphqlClient$new(
url = "<%= config[:endpoint] %>"
)
qry <- Query$new()
qry$query('TeamMatch, '{
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
}
}')
(x <- con$exec(qry$queries$TeamMatch))
data <- jsonlite::fromJSON(x)
# put data into a data frame
matches <- data$data$live_match
{
"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.
library("ghql")
library("jsonlite")
library("dplyr")
con <- GraphqlClient$new(
url = "<%= config[:endpoint] %>"
)
qry <- Query$new()
qry$query('mydata', '{
statsbomb_competition(where: {competition_area: {area_name: {_eq: "England"}}, competition_name: {_eq: "Premier League"}}) {
competition_id
competition_name
competition_area {
area_id
area_name
}
}
}')
(x <- con$exec(qry$queries$mydata))
data <- jsonlite::fromJSON(x)
# put data into a data frame
competitions <- data$data$statsbomb_competition