Squads
Learn how to get the squad information for a team.
We'll cover the following
The team squads can keep changing because of players’ injuries and personal breaks. We can keep a tab on these changes using Api-Football.
Fetch squad lists
The Squads endpoint returns the current squad of a team. The base URI for this endpoint is https://v3.football.api-sports.io/players/squads
.
Request parameters
The following parameters are used with the Squads endpoint:
Parameters | Type | Category | Description |
| Integer | Optional | This is the ID of the team whose squads we want. We can get the ID of the team using the Teams information endpoint. |
| Integer | Optional | This is the ID of the player whose teams we want in response. We can get the ID of the player using the Players endpoint. |
Note: We must use at least one of these parameters with this endpoint. Calling this endpoint without any query parameters will return an error.
Using the team
parameter with the Squads endpoint gives the squad of a team. Click the “Run” button to get the squad.
const endpointUrl = new URL('https://v3.football.api-sports.io/players/squads');const queryParameters = new URLSearchParams({team:'33' // 33 is the team id for Manchester United});headerParameters = {'x-rapidapi-host': 'v3.football.api-sports.io','x-rapidapi-key': '{{API_KEY}}'}const options = {method: 'GET',headers: headerParameters};async function fetchTeamSquad() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchTeamSquad();
Following is the code explanation:
Line 1: We set the URL to
https://v3.football.api-sports.io/players/squads
.Lines 3–10: We define the query parameters and header parameters. We can get the squads for other teams by changing the team ID in line 4.
Lines 12–15: We set the request type and appropriate header.
Lines 17–26: We define a function,
fetchTeamSquad()
. This function calls the endpoint and prints the response.
Note: We can get the team’s ID using the Teams information endpoint, as explained in the Teams Information lesson.
Using the player
parameter with the Squads endpoint gets all the teams the selected player has been a part of. Click the “Run” button to get the teams a player has played for.
const endpointUrl = new URL('https://v3.football.api-sports.io/players/squads');const queryParameters = new URLSearchParams({player:'276' // 276 is the player id of Neymar});headerParameters = {'x-rapidapi-host': 'v3.football.api-sports.io','x-rapidapi-key': '{{API_KEY}}'}const options = {method: 'GET',headers: headerParameters};async function fetchPlayersTeams() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchPlayersTeams();
Here are the modifications we’ve made to the code:
- Lines 4: We replace the
team
parameter with theplayer
parameter. We can change the player ID in line 4 to get the teams for other players. - Line 17: We change the function’s name to
fetchPlayersTeams()
.
Note: We can use the Players endpoint to get the player’s ID, as explained in the Players Information lesson.
Response fields
The table below contains some important response fields of this endpoint:
Response Fields | Type | Description |
| Object | This object contains the ID, name, and logo of the team that the event is related to. |
| Object [array] | This array contains information about the players who are part of the team's squad. It is part of the response in case the search is conducted using the |
| Object | This object contains information about the searched player. It is part of the response in case the search is conducted using the |