Teams Information

Learn how to get a team's information using Api-Football.

A football team is not just a football team; it’s a complete community where the fans share their joys and disappointments. The more we know about our team, the stronger our bond is with the other fans. Api-Football can help strengthen that bond by giving us information about our favorite team.

Fetch teams’ information

The Teams information endpoint provides the list of available teams. The base URI for this endpoint is https://v3.football.api-sports.io/teams.

Request parameters

We can use the following query parameters for this endpoint:

Parameters

Type

Category

Description

id

Integer

Optional

This is the ID of the team we want to get information for.

name

String

Optional

This is the name of the team we want to get information for.

league

Integer

Optional

This is the ID of the league whose teams' information we want. It can be retrieved using the Leagues endpoint.

season

Integer

Optional

This is the season of the league for which we want the data. The format is "YYYY."

country

String

Optional

This is the name of the country whose team we want to get information for.

search

String

Optional

These are the initials for the team or the country name. They should be a minimum of 3 characters.

Note: We need to use at least one of these parameters with this endpoint. Calling this endpoint without any query parameters will return an error.

The code in the widget below shows how we can use the GET request to retrieve a team’s information using the team’s name. Click the “Run” button to get the team’s information.

Press + to interact
const endpointUrl = new URL('https://v3.football.api-sports.io/teams');
const queryParameters = new URLSearchParams({
name:'manchester united'
});
headerParameters = {
'x-rapidapi-host': 'v3.football.api-sports.io',
'x-rapidapi-key': '{{API_KEY}}'
}
const options = {
method: 'GET',
headers: headerParameters
};
async function fetchTeamInfo() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
printResponse(response);
}
catch (error) {
printError(error);
}
}
fetchTeamInfo();

Following is a brief explanation of the code above:

  • Line 1: We define the URL of the endpoint.

  • Lines 3–5: We define the query parameters. We can get the information for other teams by changing the team name in line 4.

  • Lines 7–10: We define the headerParameters object with x-rapidapi-host and x-rapidapi-key as its elements.

  • Lines 12–15: We define the request type and set the appropriate header to be sent with the request.

  • Lines 17–26: We define a function named fetchTeamInfo() that calls the API and prints the response. In case of an error, it prints the error.

  • Line 28: We call the fetchTeamInfo() function.

With this endpoint, we can also get information for all teams from a league using the league and season parameters. The code below shows how we can use these two parameters with this endpoint. Click the “Run” button to initiate the GET request and see the teams’ information.

Note: We can’t use the league parameter without the season parameter.

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

Let's look at the modifications we've made to the code:

  • Lines 4–7: We change the query parameters. We can change the league ID in line 5 and the year we want information for in line 6 to get information for other leagues and years.

  • Line 19: We change the function's name to fetchLeagueTeams().

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

Similarly, we can search for a team using the search parameter with the Teams information endpoint. We need at least the first three characters of the team or country’s name to get information. The code below searches for a team. Click the “Run” button to get the required information.

Press + to interact
const endpointUrl = new URL('https://v3.football.api-sports.io/teams');
const queryParameters = new URLSearchParams({
search: 'evert'
});
headerParameters = {
'x-rapidapi-host': 'v3.football.api-sports.io',
'x-rapidapi-key': '{{API_KEY}}'
}
const options = {
method: 'GET',
headers: headerParameters
};
async function searchTeam() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
printResponse(response);
}
catch (error) {
printError(error);
}
}
searchTeam();

Let's look at the modifications we've made to the code:

  • Lines 3–5: We change the query parameters. We can get information about other teams by replacing evert with the initials of the other team's name in line 4. We can also search for all the teams of a country by replacing evert with the country's initials in line 4.

  • Line 17: We change the function's name to searchTeams().

Response fields

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

Response Fields

Type

Description

team

Object

This object contains information about the team.

venue

Object

This object contains information about the home ground of the team.

Note: The details about the elements in these objects are discussed  in the Response Elements lesson in the Appendix.