Algobook
- The developer's handbook
mode-switch
back-button
Buy Me A Coffee
Fri May 26 2023

How to get historical sport winners for major events in JavaScript

In this article, we will explore one of our APIs that we provide for free at Algobook. The API is called Sport winner API and are providing winners for major sport events. The API is growing for every week, and when this article was written we supported

  • UEFA Champions League
  • Super Bowl
  • Cricket World Cup
  • Stanley Cup
  • Wimbledon
  • Tour de france
  • Fifa World Cup

But as said, we are adding more data as often as we can. And we love to get feedback, so if you have any wishes on tournaments or similar that we can add to our database and provide you with, contact us here.

For fresh documentation, visit the docs page.

Explore the API

Let's take a look at some of the endpoints that we can use to get the data.

Champions League

Let's start with getting some champions league data. By calling the /sports/championsLeague, the API will return all history data. Example in JavaScript:

const response = await fetch( "https://api.algobook.info/v1/sports/championsLeague" ); const data = await response.json(); console.log(data);

And the response will look like below. I will shorten the response since it is quite a lot, but just for you to see the response data

[ { "year": "1955-56", "finalScore": "4-3", "winner": { "country": "ESP", "team": "Real Madrid" }, "loser": { "country": "FRA", "team": "Reims" }, "venue": "Parc des Princes", "audienceCount": "38,239" }, { "year": "1956-57", "finalScore": "2-0", "winner": { "country": "ESP", "team": "Real Madrid" }, "loser": { "country": "ITA", "team": "Fiorentina" }, "venue": "Santiago Bernabéu", "audienceCount": "124,000" }, ... ]

So the data is dated back to 1955 and contains the winner and loser team, as well as the venue, audience and the final score. If we want to get info for just one year, we can add the year in the endpoint like below example. Note that the format should be xxxx-yy for the year.

const response = await fetch( "https://api.algobook.info/v1/sports/championsLeague/1999-00" ); const data = await response.json(); console.log(data);

The API will now return the 1999-00 result, which is:

{ "year": "1999-00", "finalScore": "3-0", "winner": { "country": "ESP", "team": "Real Madrid" }, "loser": { "country": "ESP", "team": "Valencia" }, "venue": "Stade de France", "audienceCount": "80,000" }

Stanley cup

Let's do another one. We will now get the Stanley cup results. The idea is the same, just call the /stanleyCup endpoint, and we will get the data for all events, dated back to 1927.

const response = await fetch("https://api.algobook.info/v1/sports/stanleyCup"); const data = await response.json(); console.log(data);

And the response looks like below. I will also strip it down a bit since it is quite a lot.

[ { "season": "1927", "winningTeam": { "name": "Ottawa Senators", "coach": "Dave Gill" }, "loserTeam": { "name": "Boston Bruins", "coach": "Art Ross" }, "games": "2–0", "winningGoal": "Cy Denneny (7:30, second)" }, { "season": "1928", "winningTeam": { "name": "New York Rangers", "coach": "Lester Patrick" }, "loserTeam": { "name": "Montreal Maroons", "coach": "Eddie Gerard" }, "games": "3–2", "winningGoal": "Frank Boucher (3:35, third)" } ]

The data here will give you the winner team, loser team, total games, coaches and also who scored the winning goal.

To get only one season result, simply add /:season in the parameter.

const response = await fetch( "https://api.algobook.info/v1/sports/stanleyCup/2022" ); const data = await response.json(); console.log(data);

And then we will get below response.

{ "season": "2022", "winningTeam": { "name": "Colorado Avalanche", "coach": "Jared Bednar" }, "loserTeam": { "name": "Tampa Bay Lightning", "coach": "Jon Cooper" }, "games": "4–2", "winningGoal": "Artturi Lehkonen (12:28, second)" }

There we go!

Summary

So as stated above, we have support for Wimbledon as well, and the logic is the same with getting full historical data and also specific years. Head over to the documentation page here for all endpoints available.

We are trying to add more data and sport events as often as we can, and if you have any suggestions on what you want to have in your application, please just contact us and we will make sure to add it! Contact is found here.

Thanks for reading, and have a great day!

signatureFri May 26 2023
See all our articles