How to get head-to-head data between two teams
O endpoint /fixtures/headtohead retorna o historico de confrontos entre dois times. Neste exemplo usaremos Flamengo vs Fluminense (Fla-Flu).
The /fixtures/headtohead endpoint returns the match history between two teams. In this example we'll use Flamengo vs Fluminense.
O parametro h2h recebe os IDs dos dois times separados por hifen. O parametro last limita o numero de jogos retornados.
const API_KEY = 'YOUR_API_KEY';
const BASE = 'https://football.api.insyde.one';
async function getH2H(team1, team2, last = 10) {
const url = `${BASE}/fixtures/headtohead?h2h=${team1}-${team2}&last=${last}&key=${API_KEY}`;
const res = await fetch(url);
return res.json();
}
// Flamengo (127) vs Fluminense (124) — last 10 matches
const data = await getH2H(127, 124, 10);
console.log(`Total meetings: ${data.results}`);
Resposta / Response:
{
"get": "fixtures/headtohead",
"parameters": { "h2h": "127-124", "last": "10" },
"results": 10,
"response": [
{
"fixture": {
"id": 1234567,
"date": "2025-10-19T20:00:00+00:00",
"venue": { "name": "Maracana", "city": "Rio de Janeiro" }
},
"teams": {
"home": { "id": 127, "name": "Flamengo", "winner": true },
"away": { "id": 124, "name": "Fluminense", "winner": false }
},
"goals": { "home": 3, "away": 1 }
},
...
]
}
function calcStats(matches, teamId) {
let wins = 0, losses = 0, draws = 0;
matches.forEach(m => {
const isHome = m.teams.home.id === teamId;
const gf = isHome ? m.goals.home : m.goals.away;
const ga = isHome ? m.goals.away : m.goals.home;
if (gf > ga) wins++;
else if (gf < ga) losses++;
else draws++;
});
return { wins, losses, draws };
}
const flaStats = calcStats(data.response, 127);
console.log(flaStats);
// { wins: 6, losses: 1, draws: 3 }
h2h — IDs dos times separados por hifen (obrigatorio) / Team IDs separated by hyphen (required)last — Numero de ultimos jogos / Number of last matchesseason — Filtrar por temporada / Filter by seasonleague — Filtrar por liga / Filter by leagueh2h com league e season para ver apenas os confrontos em uma competicao especifica.
h2h with league and season to see only meetings in a specific competition.