Subscriptions to Live Match Events
Use the viewing matches query to discover a specific match_id
value.
Update the match_id
value for a Hudl Statsbomb live match and press the play button in the middle of the page.
subscription MatchSubscription {
live_match_event(
where: {match_id: {_eq: 123}},
order_by: {period: desc, index: desc}) {
id
name
team_id
player_id
timestamp
}
}
A GraphQL subscription is now listening for all events in a match with an id of 123
, ordered by the most recent events. Every time a new event is captured the response is updated with the most recent events at the top.
{
"data": {
"live_match_event": [
{
"id": "0f5052ef-9793-418e-8fe3-0c25fcdcad5b",
"name": "out",
"team_id": 222,
"player_id": null,
"timestamp": "00:47:27.4+00"
},
{
"id": "74d24839-20b0-4c1b-a36b-c53135800ed6",
"name": "shot",
"team_id": 222,
"player_id": 28409,
"timestamp": "00:47:26.196+00"
}
]
}
}
Because you'll likely want to test any subscriptions you make without having to wait until a Live match is happening, we have added a live_simulate_match
function that allows you to specify a match_id
and a kickoff
time, and it will replay events as if the match were happening from that time. An optional speed
parameter changes how fast events are replayed - 1.0 will be real-time, 2.0 will be twice as fast, 0.5 will be half as fast etc. Please note that this simulation is not currently an exact replica of what would happen during a real game. For example, events don't always appear fully formed in the API, they might later be updated with more information. Also in some cases an event will be deleted and replaced by another one.
subscription MatchSimulation {
live_simulate_match(
args: {match_id: 123,
kickoff: "2022-09-15 1600 BST",
speed: 1.0}) {
id
name
team_id
player_id
timestamp
}
}
The fields you can request and the output from this function are exactly the same as a normal event subscription.