Players Information
Learn how to get the details of a player using Api-Football.
We'll cover the following
We enjoy learning every detail about our favorite player. Whether the information is related to his profile or his statistics, we like to keep track of it all. Api-Football can help us gather that information.
Fetch player information
The Players endpoint returns information about the players with available profiles and statistics.
Note: It’s possible that a player has statistics for two teams in the same season in case of transfers.
This endpoint uses a pagination system; we can navigate between the different pages using the page
parameter.
Request parameters
The following query parameters can be used with the Players endpoint.
Parameters | Type | Category | Description |
| Integer | Required | This is the ID of the player whose information we want. We can get the IDs of the player using the Players endpoint. |
| Integer | Optional | This is the ID of the team whose players' information we want in response. We can get the IDs of the team using the Teams endpoint. |
| Integer | Optional |
|
| Integer | Optional | This is the year we want to see the information for. The format is "YYYY." It requires the fields: |
| String | Optional | This is the initials of the player for whom we want the information. It must be at least four characters. It requires the |
| Integer | Optional | This is the page number we want to see. The default value for this parameter is |
We can use the team
and search
parameters with this endpoint to search for information about a player. The widget below contains the code for searching for a player. Click the “Run” button to get the players’ information.
const endpointUrl = new URL('https://v3.football.api-sports.io/players');const queryParameters = new URLSearchParams({search: 'cavani',team: '85' // 85 is the team id for Paris Saint German});headerParameters = {'x-rapidapi-host': 'v3.football.api-sports.io','x-rapidapi-key': '{{API_KEY}}'}const options = {method: 'GET',headers: headerParameters};async function searchPlayer() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}searchPlayer();
Here is the code explanation:
Line 1: We set the URL to
https://v3.football.api-sports.io/players
.Lines 3–11: We define the query parameters and header parameters. We can change the initials of the player's name in line 4 to get information about other players from the same team. We can get information about other teams' players by changing both the player's name in line 4 and the team ID in line 5, respectively.
Lines 13–16: We set the request type and appropriate header.
Lines 18–27: We define a function,
searchPlayer()
, that calls the endpoint and prints the response.
Note: We can obtain the team’s ID using the Teams information endpoint, as explained in the previous Teams Information lesson.
We can use the id
and season
parameters with this endpoint to get information about a player for a single season. The above code has been modified in the widget below to get information about a player for a single season. Click the “Run” button to get the player’s information.
const date = new Date();const endpointUrl = new URL('https://v3.football.api-sports.io/players');const queryParameters = new URLSearchParams({id: '19088', // 19088 is the player id of Dean Hendersonseason: date.getFullYear()});headerParameters = {'x-rapidapi-host': 'v3.football.api-sports.io','x-rapidapi-key': '{{API_KEY}}'}const options = {method: 'GET',headers: headerParameters};async function fetchPlayerInfo() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchPlayerInfo();
Let’s look at how we’ve modified the code:
- Lines 4–7: We change the query parameters. We can change the player ID in line 5 to get information for other players.
- Line 19: We change the function’s name to
fetchPlayerInfo()
.
Similarly, we can use the team
and season
parameters with this endpoint to get information about a team’s players for a single season. The widget below contains the modified code. Click the “Run” button to get the players’ information.
const date = new Date;const endpointUrl = new URL('https://v3.football.api-sports.io/players');const queryParameters = new URLSearchParams({team: '85', // 85 is the team id for Paris Saint Germanseason: date.getFullYear()});headerParameters = {'x-rapidapi-host': 'v3.football.api-sports.io','x-rapidapi-key': '{{API_KEY}}'}const options = {method: 'GET',headers: headerParameters};async function fetchPlayerInfo() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchPlayerInfo();
We change the query parameters in lines 4–7 to get the required information. We can get the information for other seasons by changing the year in line 6.
Response fields
The table below contains some important response fields of this endpoint:
Response Fields | Type | Description |
| Object | This object contains information about the searched player. |
| Object | This object contains statistics related to the searched player. |
Note: The detail about the elements in these objects is discussed in the Response Elements lesson in the Appendix.