How-to build a livescore website
Welcome to our how-to guide about building a livescore website.
Livescore websites are one of the most popular applications. But, what exactly is a livescore website?
As its name suggests, livescore websites are website applications primarily focused on showing the livescores of sports matches.
Livescores are updated in real-time. So, a football livescore website should, for instance, tell you the real-time live score, the minute of the match, the current score, and its starting time.
You are going to need the following tools:
- Sportmonks API token
- Code editor (Visual studio used in examples)
- Postman (optional)
You can find a link to another article where we discuss the tools in-depth in our Developer Tools Guide.
Now that we have all our tools, we can start planning what we want to show our audience.
Which leagues pique your interest? Do you want to show as many leagues as possible? Or do you only want to show specific leagues, like the English Premier League?
These are all things to consider, but you have to make sure that the leagues you choose are available in your plan. See our coverage page to see which leagues are included per plan.
You can request all the leagues in your current plan through our get all leagues endpoint.
If there are no ongoing matches in your plan, the livescore API will return nothing back.
Now that you have decided on which leagues you would like to show, the next step is to choose what data would be useful to offer.
Most livescore websites show:
- Date of the match
- What time the match starts
- The home and away teams
- Status of the game: first half, half time, match has ended, minute by minute, etc.
- Live score
- Events such as goals, cards
- Team logos, league logos, country flag
All of this seems like a lot of data to request but fear not because our livescore API will be able to return all of that data in a speedy and accurate manner. Moreover, the API is highly flexible, since it only returns the data you requested.
If you require more match data such as lineups and match statistics, please refer to the how-to build a match page.
Our API 3.0 has three endpoints for getting livescores:
- GET All Inplay Livescores: returns all the inplay fixtures.
- GET All Livescores: returns the fixtures 15 minutes before the game starts. It will also disappear 15 minutes after the game is finished.
- GET Latest Updated Livescores: returns all livescores that have received updates within 10 seconds.
In this how-to guide, we’ll go with the GET All Inplay Livescores endpoint.
https://api.sportmonks.com/v3/football/livescores/inplay?api_token=YOUR_TOKEN
Now that we have the request ready, it’s time to enrich the URL with various includes, based on the choices you made in step 3.
An example of a very common request is to include participants, goals scored, substitutions, and yellow/red cards.
For convenience’s sake, we have assembled these three includes into one include called events.
https://api.sportmonks.com/v3/football/livescores/inplay?api_token=YOUR_TOKEN&include=scores;events;participants;periods
Ultimately, you will be the one to build the livescore website, so feel free to add whatever includes you want. You can add as many or as little as you would like.
For example, we’ll analyze a match (fixture id: 18494085) in the 2022 World Cup between Portugal (team id: 18701) and Uruguay (team id: 15251). Below you can find the response with its events.
Livescores
Fixture by ID
Response
https://api.sportmonks.com/v3/football/livescores/inplay?api_token=YOUR_TOKEN&include=events;participants
https://api.sportmonks.com/v3/football/fixtures/18494085?api_token=YOUR_TOKEN&include=scores;events;participants
{
"data": {
"id": 18494085,
"sport_id": 1,
"league_id": 732,
"season_id": 18017,
"stage_id": 77452386,
"group_id": 246698,
"aggregate_id": null,
"round_id": 269276,
"state_id": 5,
"venue_id": 343341,
"name": "Portugal vs Uruguay",
"starting_at": "2022-11-28 19:00:00",
"result_info": "Portugal won after full-time.",
"leg": "1/1",
"details": null,
"length": 90,
"placeholder": false,
"last_processed_at": "2023-03-02 17:49:00",
"has_odds": true,
"starting_at_timestamp": 1669662000,
"scores": [
{
"id": 11089540,
"fixture_id": 18494085,
"type_id": 1,
"participant_id": 15251,
"score": {
"goals": 0,
"participant": "away"
},
"description": "1ST_HALF"
},
{
"id": 11089541,
"fixture_id": 18494085,
"type_id": 1,
"participant_id": 18701,
"score": {
"goals": 0,
"participant": "home"
},
"description": "1ST_HALF"
},
{
"id": 11089542,
"fixture_id": 18494085,
"type_id": 2,
"participant_id": 15251,
"score": {
"goals": 0,
"participant": "away"
},
"description": "2ND_HALF"
},
{
"id": 11089543,
"fixture_id": 18494085,
"type_id": 2,
"participant_id": 18701,
"score": {
"goals": 2,
"participant": "home"
},
"description": "2ND_HALF"
},
{
"id": 11089544,
"fixture_id": 18494085,
"type_id": 1525,
"participant_id": 15251,
"score": {
"goals": 0,
"participant": "away"
},
"description": "CURRENT"
},
{
"id": 11089545,
"fixture_id": 18494085,
"type_id": 1525,
"participant_id": 18701,
"score": {
"goals": 2,
"participant": "home"
},
"description": "CURRENT"
}
],
"participants": [
{
"id": 15251,
"sport_id": 1,
"country_id": 158,
"venue_id": 10900,
"gender": "male",
"name": "Uruguay",
"short_code": "URU",
"image_path": "https://cdn.sportmonks.com/images/soccer/teams/19/15251.png",
"founded": 1900,
"type": "national",
"placeholder": false,
"last_played_at": "2022-12-02 15:00:00",
"meta": {
"location": "away",
"winner": false,
"position": 3
}
},
{
"id": 18701,
"sport_id": 1,
"country_id": 20,
"venue_id": 14455,
"gender": "male",
"name": "Portugal",
"short_code": "POR",
"image_path": "https://cdn.sportmonks.com/images/soccer/teams/13/18701.png",
"founded": 1914,
"type": "national",
"placeholder": false,
"last_played_at": "2022-12-10 15:00:00",
"meta": {
"location": "home",
"winner": true,
"position": 1
}
}
],
"events": [
{
"id": 70703968,
"fixture_id": 18494085,
"period_id": 4519962,
"participant_id": 15251,
"type_id": 19,
"section": "event",
"player_id": 333797,
"related_player_id": null,
"player_name": "Rodrigo Bentancur ",
"related_player_name": null,
"result": null,
"info": "Foul",
"addition": null,
"minute": 6,
"extra_minute": null,
"injured": null,
"on_bench": false,
"coach_id": null,
"sub_type_id": null
},
We used the livescore request at the time, but you can refer to the fixture by id request for the same output.
Events will show all the goals, cards, and substitutions.
The events shown in the response is a yellow card in the 6th minute for Rodrigo Bentancur.
Let's say, we want to make a dedicated page just for the World Cup (league id: 732) on our livescore website, but our plan has over 600 different leagues.
On Saturdays, there are a lot of active games. However, we only want the data pertaining to the World Cup, so we can filter out everything else. We have discussed filtering in a previous tutorial.
To filter you would need to add
&filters=fixtureLeagues:732
to your request to complete the filter. Last modified 6mo ago