Top Scorers

Learn how we can get the top scorers using Api-Football.

Which player is leading the race to win the golden boot is one of the most searched-for statistics by fans. Api-Football can help us retrieve the list of top scorers for all available leagues.

We get the 20 top scorers for a league or cup using the Top Scorers endpoint. This endpoint provides the players’ information and their statistics, including the number of appearances, the number of shots taken, and the number of goals scored. The base URI for this endpoint is https://v3.football.api-sports.io/players/topscorers.

This endpoint is updated several times per week.

In case the players have a similar number of goals, they’re ranked based on the following criteria:

  1. The player that has scored fewer penalties.
  2. The player that has delivered more assists.
  3. The player that scored their goals in a higher number of matches.
  4. The player that played fewer minutes.
  5. The player that is part of the higher-ranked team.
  6. The player that received fewer red cards.
  7. The player that received fewer yellow cards.

Request parameters

We can use the following parameters with this endpoint:

Parameters

Type

Category

Description

league

Integer

Required

This is the ID of the league whose top scorers we want. We can get the ID of a league using the Leagues endpoint.

season

Integer

Required

This is the year we want to see the top scorer for. The format for this input is "YYYY."

We use the league and season parameters with the Top Scorers endpoint to get the top scorers of a league for the specified season.

Press + to interact
const date = new Date();
const endpointUrl = new URL('https://v3.football.api-sports.io/players/topscorers');
const queryParameters = new URLSearchParams({
league:'61', // 61 is the league id for France's League 1
season: date.getFullYear()
});
headerParameters = {
'x-rapidapi-host': 'v3.football.api-sports.io',
'x-rapidapi-key': '{{API_KEY}}'
}
const options = {
method: 'GET',
headers: headerParameters
};
async function fetchTopScorers() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
printResponse(response);
}
catch (error) {
printError(error);
}
}
fetchTopScorers();

Following is the code explanation:

  • Line 2: We set the URL to https://v3.football.api-sports.io/players/topscorers.

  • Lines 4–12: We define the query parameters and header parameters. We can change the league ID in line 5 to get top scorers from a different league. To get the top scorers for a different season, we will change the year in line 6.

  • Lines 14–17: We set the request type and appropriate header.

  • Lines 19–28: We define a function, fetchTopScorers(), that calls the endpoint and prints the response.

Note: We can get the league ID using the Leagues endpoint, as explained in the Support Endpoints lesson in the Appendix.

Response fields

The table below contains some important response fields of this endpoint:

Response Fields

Type

Description

player

Object

This contains information about the top scorers by rank.

statistics

Object

This contains stats related to the player.

Note: The detail about the elements in these objects is discussed in the Response Elements lesson in the Appendix.