Skip to content

Commit 4a0a812

Browse files
committed
Add an optional argument for API cookie
1 parent 44c6849 commit 4a0a812

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# fflr 2025.0.1
22

33
* Update to 2025 API endpoints and update package data.
4+
* Added the `cookie` argument to `ffl_api()` which can be passed to any function
5+
through the `...` argument. The cookie is needed to retrieve historical data
6+
(using `leagueHistory = TRUE` is no longer enough). The `espn_s2` cookie can
7+
be obtained from your browser's developer tools. This is a very clunky system
8+
and I'm working on an easier system.
49

510
# fflr 2.3.1
611

R/api.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
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
@@ -29,7 +31,8 @@
2931
#' @keywords internal
3032
#' @export
3133
ffl_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)

man/ffl_api.Rd

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)