Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working Example #244

Open
jlag34 opened this issue Jun 15, 2024 · 0 comments
Open

Working Example #244

jlag34 opened this issue Jun 15, 2024 · 0 comments

Comments

@jlag34
Copy link

jlag34 commented Jun 15, 2024

Is there a very basic working example you could give me? I have the follow code:

const { Client } = require('espn-fantasy-football-api/node');
const axios = require('axios')

const leagueId = 30031
const seasonId = 2023

// const espnS2 = my espnS2 code
// const SWID = my SWID code

async function getLeagueData() {
  try {

    // const routeBase = `https://site.api.espn.com/${seasonId}/segments/0/leagues/${leagueId}`;
    // const routeParams = `?view=mMatchup&view=mMatchupScore&scoringPeriodId=${3}`;
    // const route = `${routeBase}${routeParams}`;
    // const data = await axios.get(route)
    // console.log('DATA : ', data)
    const client = new Client({ leagueId });

  //   // Fetch league info
    const leagueInfo = await client.getTeamsAtWeek({ seasonId, scoringPeriodId: 1 });
    console.log('League Info:', JSON.stringify(leagueInfo, null, 2));

  //   // Fetch teams (users) in the league
  //   const teams = await client.getTeamsAtWeek({ seasonId, scoringPeriodId: 1 });
  //   console.log('Teams:', JSON.stringify(teams, null, 2));

  //   // Fetch rosters in the league
  //   const rosters = await client.getBoxscoreForWeek({ seasonId, scoringPeriodId: 1 });
  //   console.log('Rosters:', JSON.stringify(rosters, null, 2));
  } catch (error) {
      console.error('Error fetching data:', error);
  }
}

getLeagueData()

The league id is just one I found on Google:

https://fantasy.espn.com/football/league?leagueId=30031

When I run this code, I just get back an empty array. When I try to use the axios version I get an error. When I use the client to put in my own person league, I also get an empty array. I made the league public but I also tried with the two codes and still got nothing.

I'm just looking to be able to get the league settings, rosters, and users based on a league id. Any way you can point me in the right direction? I had GPT look at the repo but still no luck. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant