1616# ' @param scoringPeriodId Integer week of NFL season. By default, `NULL` will
1717# ' use the current week (see [ffl_week()]). Scoring periods are always one
1818# ' week in length, whereas matchups might be longer.
19+ # ' @param cookie The alphanumeric `espn_s2` cookie string from a signed-inn
20+ # ' session. As of 2025, this cookie is required to retrieve historical data.
1921# ' @param ... Additional queries passed to [httr::GET()]. Arguments are
2022# ' converted to a named list and passed to `query` alongside `view`.
2123# ' @examples
2931# ' @keywords internal
3032# ' @export
3133ffl_api <- function (leagueId = ffl_id(), view = NULL , leagueHistory = FALSE ,
32- seasonId = 2025 , scoringPeriodId = NULL , ... ) {
34+ seasonId = 2025 , scoringPeriodId = NULL , cookie = NULL ,
35+ ... ) {
3336 dots <- list (... , scoringPeriodId = scoringPeriodId )
3437 age_path <- ifelse(
3538 test = isTRUE(leagueHistory ),
@@ -45,11 +48,12 @@ ffl_api <- function(leagueId = ffl_id(), view = NULL, leagueHistory = FALSE,
4548 url = " https://lm-api-reads.fantasy.espn.com" ,
4649 path = paste(" apis/v3/games/ffl" , age_path , leagueId , sep = " /" ),
4750 query = view ,
48- leagueHistory = leagueHistory
51+ leagueHistory = leagueHistory ,
52+ cookie = cookie
4953 )
5054}
5155
52- try_json <- function (url , path = " " , query = NULL , leagueHistory = NULL ) {
56+ try_json <- function (url , path = " " , query = NULL , cookie = NULL , leagueHistory = NULL ) {
5357 resp <- httr :: RETRY(
5458 verb = " GET" ,
5559 url = ifelse(
@@ -60,7 +64,8 @@ try_json <- function(url, path = "", query = NULL, leagueHistory = NULL) {
6064 query = query ,
6165 httr :: accept_json(),
6266 httr :: user_agent(" https://github.com/k5cents/fflr/" ),
63- terminate_on = c(400 : 417 )
67+ terminate_on = c(400 : 417 ),
68+ httr :: set_cookies(espn_s2 = cookie )
6469 )
6570 if (httr :: http_type(resp ) != " application/json" ) {
6671 stop(" API did not return JSON" , call. = FALSE )
0 commit comments