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

getTeamsAtWeek returning error with years before 2018 #175

Closed
cmjarrett opened this issue Oct 2, 2020 · 2 comments
Closed

getTeamsAtWeek returning error with years before 2018 #175

cmjarrett opened this issue Oct 2, 2020 · 2 comments

Comments

@cmjarrett
Copy link
Contributor

cmjarrett commented Oct 2, 2020

When using the Client.getTeamsAtWeek() function for league stats prior to 2018, the api fails with a 404.

(node:24828) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
at createError (C:\scratch\GitHub\GentlemensLeague\node_modules\espn-fantasy-football-api\node-dev.js:1014:15)
at settle (C:\scratch\GitHub\GentlemensLeague\node_modules\espn-fantasy-football-api\node-dev.js:1289:12)
at IncomingMessage.handleStreamEnd (C:\scratch\GitHub\GentlemensLeague\node_modules\espn-fantasy-football-api\node-dev.js:361:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:24828) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:24828) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I've found that I can get the relevent Teams map by utilizing the same endpoint as the getHistoricalScoreboardForWeek() api, 'https://fantasy.espn.com/apis/v3/games/ffl/leagueHistory/' and then building the Teams array.

--but I thought I would at least let anyone else know that it is possible to get historical information at least to 2011.

This is the hacky temporary workaround I made in node-dev.js if anyone needs it. I'll try to mock up a pull request that isn't my hack, maybe add a getHistoricalTeamsAtWeek() function instead for those years < 2018

 {
    key: "getTeamsAtWeek",
    value: function getTeamsAtWeek(_ref5) {
      var _this4 = this;
      console.log(_ref5.seasonId);
      if(_ref5.seasonId > 2017) {
        var seasonId = _ref5.seasonId,
        scoringPeriodId = _ref5.scoringPeriodId;

        var route = this.constructor._buildRoute({
          base: "".concat(seasonId, "/segments/0/leagues/").concat(this.leagueId),
          params: "?scoringPeriodId=".concat(scoringPeriodId, "&view=mRoster&view=mTeam")
        });
        console.log(route);

        return axios__WEBPACK_IMPORTED_MODULE_4___default.a.get(route, this._buildAxiosConfig()).then(function (response) {
          var data = lodash_get__WEBPACK_IMPORTED_MODULE_3___default()(response.data, 'teams');

          return lodash_map__WEBPACK_IMPORTED_MODULE_1___default()(data, function (team) {
            return _team_team__WEBPACK_IMPORTED_MODULE_9__["default"].buildFromServer(team, {
              leagueId: _this4.leagueId,
              seasonId: seasonId
            });
          });
        });
      } else {
        var _this4 = this;

        var seasonId = _ref5.seasonId,
            matchupPeriodId = _ref5.scoringPeriodId,
            scoringPeriodId = _ref5.scoringPeriodId;
  
        var route = this.constructor._buildRoute({
          base: "".concat(this.leagueId),
          params: "?scoringPeriodId=".concat(scoringPeriodId, "&seasonId=").concat(seasonId) + '&view=mMatchupScore&view=mScoreboard&view=mSettings&view=mTopPerformers&view=mTeam'
        });
  
        var axiosConfig = this._buildAxiosConfig({
          baseURL: 'https://fantasy.espn.com/apis/v3/games/ffl/leagueHistory/'
        });
        console.log(route);
  
        return axios__WEBPACK_IMPORTED_MODULE_4___default.a.get(route, axiosConfig).then(function (response) {
          var data = lodash_get__WEBPACK_IMPORTED_MODULE_3___default()(response.data[0], 'teams');it 
  
          return lodash_map__WEBPACK_IMPORTED_MODULE_1___default()(data, function (team) {
            return _team_team__WEBPACK_IMPORTED_MODULE_9__["default"].buildFromServer(team, {
              leagueId: _this4.leagueId,
              seasonId: seasonId
            });
          });
        });
      }
    }
@cmjarrett
Copy link
Contributor Author

cmjarrett commented Oct 2, 2020

I'm using Team objects so that I can display league standings across multiple years. While I could retrieve the historical boxscores and recreate the standings, and in fact that was my initial approach once I found the getTeamsAtWeek() api didn't work for older years. I eventually looked into each endpoint themselves to see what data was returned, and to my surprise I discovered that the endpoint simply gave me all the information I wanted (but that getHistoricalScoreboardForWeek function didn't parse and return the Team object data).

@mkreiser
Copy link
Owner

Added in #233 (v1.5.0)

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

2 participants