Files
ScoreSpot/src/assets/routes/league-pages/get-team-names-for-registry.js

22 lines
608 B
JavaScript
Raw Normal View History

2024-04-15 11:04:16 -06:00
const axios = require('axios');
const fetchTeamNames = async (selectedLeague) => {
try {
const response = await axios({
url: `http://api.football-data.org/v4/competitions/${selectedLeague}/teams`,
method: 'GET',
headers: {
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3',
},
});
2024-04-15 11:04:16 -06:00
const teams = response.data.teams.map(team => team.name);
return teams;
} catch (error) {
console.error('Error fetching teams data:', error);
return [];
}
};
module.exports = fetchTeamNames;