How to get all teams and players from a league ID
Neste tutorial veremos a forma mais eficiente de buscar todos os times e jogadores de uma competição usando Node.js (ou qualquer ambiente com fetch).
In this tutorial we'll see the most efficient way to get all teams and players from a competition using Node.js (or any environment with fetch).
Vamos usar o Brasileirão Série A (league ID 71), temporada 2025.
Caso queira usar outra liga mas não saiba o ID, consulte o endpoint /leagues.
coverage no endpoint /leagues antes de fazer chamadas.
coverage field in the /leagues endpoint before making calls.
Uma única chamada ao endpoint /teams com os parâmetros league e season retorna todos os times.
const API_KEY = 'YOUR_API_KEY';
const BASE = 'https://football.api.insyde.one';
async function getTeams(league, season) {
const url = `${BASE}/teams?league=${league}&season=${season}&key=${API_KEY}`;
const res = await fetch(url);
const data = await res.json();
return data.response;
}
// Brasileirão 2025
const teams = await getTeams(71, 2025);
console.log(`Total teams: ${teams.length}`);
A API retorna os 20 times da Série A com seus estádios / The API returns all 20 Série A teams with their venues:
{
"get": "teams",
"parameters": { "league": "71", "season": "2025" },
"errors": [],
"results": 20,
"paging": { "current": 1, "total": 1 },
"response": [
{
"team": {
"id": 131,
"name": "Corinthians",
"code": "COR",
"country": "Brazil",
"founded": 1910,
"national": false,
"logo": "https://football.api.insyde.one/football/teams/131.png"
},
"venue": {
"id": 243,
"name": "Neo Química Arena",
"address": "Avenida Miguel Ignácio Curi, 111",
"city": "São Paulo",
"capacity": 49205,
"surface": "grass",
"image": "https://football.api.insyde.one/football/venues/243.png"
}
},
...
]
}
O endpoint /players usa paginação com 20 resultados por página.
Podemos chamar com league e season para buscar todos os jogadores da competição de uma vez, iterando pelas páginas.
The /players endpoint uses pagination with 20 results per page.
We can call it with league and season to get all competition players at once, iterating through pages.
A primeira chamada retorna a página 1 e informa o total de páginas:
{
"paging": {
"current": 1,
"total": 39
},
"results": 20,
"response": [ ... ]
}
Precisamos percorrer da página 1 até a última (39 neste exemplo). A melhor abordagem é uma função recursiva que detecta automaticamente o total de páginas.
async function fetchApi(endpoint, params = {}) {
params.key = API_KEY;
const qs = new URLSearchParams(params).toString();
const res = await fetch(`${BASE}/${endpoint}?${qs}`);
return res.json();
}
async function getAllPlayers(league, season, page = 1, allPlayers = []) {
const data = await fetchApi('players', { league, season, page });
allPlayers.push(...data.response);
if (data.paging.current < data.paging.total) {
// Delay to respect rate limit (every 2 pages, wait 1s)
if (page % 2 === 0) {
await new Promise(r => setTimeout(r, 1000));
}
return getAllPlayers(league, season, page + 1, allPlayers);
}
return allPlayers;
}
// Get all players from Brasileirão 2025
const players = await getAllPlayers(71, 2025);
console.log(`Total players: ${players.length}`);
setTimeout a cada 2 páginas evita erros 429 Too Many Requests.
setTimeout every 2 pages avoids 429 Too Many Requests errors.
fetchApi() monta a URL com query params e chama a API / builds the URL with query params and calls the APIgetAllPlayers() busca a primeira página e acumula os resultados / fetches the first page and accumulates resultspaging.current < paging.total, incrementa a página e chama a si mesma / if there are more pages, it increments and calls itself
Exemplo: se a API retornar 39 páginas, teremos (38 × 20) + 11 = 771 jogadores com todas as suas estatísticas da temporada.
const API_KEY = 'YOUR_API_KEY';
const BASE = 'https://football.api.insyde.one';
async function fetchApi(endpoint, params = {}) {
params.key = API_KEY;
const qs = new URLSearchParams(params).toString();
const res = await fetch(`${BASE}/${endpoint}?${qs}`);
return res.json();
}
async function getAllPlayers(league, season, page = 1, allPlayers = []) {
const data = await fetchApi('players', { league, season, page });
allPlayers.push(...data.response);
if (data.paging.current < data.paging.total) {
if (page % 2 === 0) {
await new Promise(r => setTimeout(r, 1000));
}
return getAllPlayers(league, season, page + 1, allPlayers);
}
return allPlayers;
}
async function main() {
const LEAGUE = 71; // Brasileirão Série A
const SEASON = 2025;
// 1. Get all teams
const teamsData = await fetchApi('teams', { league: LEAGUE, season: SEASON });
console.log(`Teams: ${teamsData.results}`);
for (const { team, venue } of teamsData.response) {
console.log(` ${team.name} — ${venue.name} (${venue.city})`);
}
// 2. Get all players (with pagination)
const players = await getAllPlayers(LEAGUE, SEASON);
console.log(`Players: ${players.length}`);
}
main();