How to get top scorers from a league
Neste tutorial veremos como buscar a lista de artilheiros e montar um leaderboard visual.
In this tutorial we'll see how to get the top scorers list and build a visual leaderboard.
Uma unica chamada ao endpoint /players/topscorers retorna ate 20 jogadores ordenados por gols.
const API_KEY = 'YOUR_API_KEY';
const BASE = 'https://football.api.insyde.one';
async function getTopScorers(league, season) {
const url = `${BASE}/players/topscorers?league=${league}&season=${season}&key=${API_KEY}`;
const res = await fetch(url);
const data = await res.json();
return data.response;
}
const scorers = await getTopScorers(71, 2025);
console.log(`Top scorers: ${scorers.length}`);
Cada item retornado possui as estatisticas completas do jogador na temporada / Each item has the player's full season statistics:
{
"player": {
"id": 47381,
"name": "Pedro",
"firstname": "Pedro",
"lastname": "Guilherme",
"age": 27,
"nationality": "Brazil",
"photo": "https://football.api.insyde.one/football/players/47381.png"
},
"statistics": [
{
"team": { "id": 127, "name": "Flamengo" },
"league": { "id": 71, "name": "Serie A" },
"games": { "appearences": 35, "rating": "7.8" },
"goals": { "total": 22, "assists": 5 },
"shots": { "total": 95, "on": 48 },
"passes": { "accuracy": 78 }
}
]
}
function buildLeaderboard(scorers) {
scorers.forEach((item, i) => {
const p = item.player;
const s = item.statistics[0];
console.log(
`#${i + 1} ${p.name} (${s.team.name}) — ${s.goals.total} goals, ${s.goals.assists} assists`
);
});
}
buildLeaderboard(scorers);
#1 Pedro (Flamengo) — 22 goals, 5 assists
#2 Yuri Alberto (Corinthians) — 19 goals, 4 assists
#3 Flaco Lopez (Palmeiras) — 17 goals, 3 assists
...
/players/topassists — Top passadores / Top assist providers/players/topyellowcards — Mais cartoes amarelos / Most yellow cards/players/topredcards — Mais cartoes vermelhos / Most red cardscoverage.top_scorers no endpoint /leagues indica se a liga tem dados de artilheiros. Verifique antes de chamar.
coverage.top_scorers field in /leagues indicates if the league has scorer data. Check before calling.