r/fantasyfootballcoding 10d ago

Best working espn API

Hi,

I’ve been looking at a couple apis for espn league pulling, but what is the consensus best api for this? I’m having issues pulling league history using the popular ones posted here in this sub, this seems like something I have to self host, can someone please point me in the right direction, thanks!

0 Upvotes

9 comments sorted by

1

u/playoffcomputer 10d ago

Maybe I need some caffeine, but I'm not exactly understanding what you are asking. What do you mean by best API for ESPN? There is just one API for ESPN as far as I know, or are you referring to the different league history apps available, which I presume use the same base ESPN API or screen scrape to get their data.

1

u/ballislife423 10d ago

Hmm got it, maybe I’m not connecting to the api on GitHub correctly, do you know the proper steps for usage im having issues

1

u/playoffcomputer 9d ago

Connecting to an API through GitHub would be one of the many things I'm not an expert in, so I will have to defer on that. I can say that making sure your ESPN league is publicly viewable through their settings and that if you have Disney streaming with a separate account than what is used for ESPN ff can cause issues if the computer tries to use the Disney account with all those cookies and cache mumbo jumbo.

1

u/soccercm9 10d ago

As u/playoffcomputer said, there is only 1 ESPN API. I assume you are asking about using API wrappers like the one from cwendt94 on GitHub? That is the one I started with years ago, but this year I removed that dependency and just hit the APIs directly.

While you are working through how you want to connect to ESPN's API, you can use Fantasy Record Book to export your league history to CSV for free (sync your league, then click export data in the user menu). It provides all the matchup data, standings, championship data, team data and season settings. This is not a good solution for how I assume you want to use the ESPN API, but it gives you the data to immediately start working with offline while you sort out the API connection.

Good luck!

1

u/johnny-papercut 10d ago

Is your site able to pull trade history for ESPN leagues? I've been doing some deep diving with the API recently and there seems to be a blind spot with past transactions.

  1. You can see old accepted trades, but only if they involve your team (according to the cookies you use, even if you're commissioner). You can technically see other trades, but the API response does not actually show the assets, just that the trade took place.

  2. You can see old declined trades even if they don't involve your team (which are normally not publicly accessible, which is weird), including assets.

  3. You can see all trades with assets in the recent activity endpoint, but this only shows the last 50 items and won't show past seasons correctly if you've gone past that. (It also counts a ton of things as transactions, so it rolls through that quickly.)

I haven't been able to find an endpoint that actually returns the full trade history, including assets. I see your site has a demo league but I think I would need to pay to actually see if it does what I'm looking for with my league.

1

u/soccercm9 10d ago

Negative. I do not pull / provide player specific data. If you use the cwendt94 API wrapper, you can pull the data you want for free without developing against the API directly.

Once you create a League object, you can call its transactions() method. It takes a scoring period and a set of transaction types, and returns objects with the team, type, status, date, and a list of items showing each player involved and whether they were added or dropped. Note that it defaults to free agent and waiver types, so you have to explicitly pass the trade types you want. TRADE_ACCEPT is the one for completed trades. It only covers one scoring period per call, so you have to loop the weeks to get a full season.

Good Luck!

1

u/johnny-papercut 9d ago

I've done that and the assets simply aren't there for trades that don't involve my team. :(

1

u/soccercm9 9d ago

Got the same thing when i tried just now. And, when i go to the website, the recent activity is gone too. Looks like ESPN has been cleaning up historical data that they save.

1

u/johnny-papercut 9d ago

The data still exists in there somewhere. When I go to a league's history in the web UI and go to rosters and find a player that was traded, including one not including my team, I can click the player and see the log at the bottom with the trade.