API Instructions

June 12, 2018

(This article was first published on R – Fantasy Football Analytics, and kindly contributed to R-bloggers)

The Fantasy Football Analytics API allows developers to programmatically access our data in JSON format. Users must pay for a standalone subscription to obtain a unique API key granting access. You must have an account on the Fantasy Football Analytics web app in order to subscribe to the API (simply click the “Register” tab in the navigation bar at http://apps.fantasyfootballanalytics.net/ to set up an account if you don’t already have one).

There are two API subscription types, “Basic” and “Premier”, both of which allow access to seasonal and weekly projections for previous seasons and to seasonal projections for the current season. Only the “Premier” subscription allows access to weekly projections for the current season. Both subscriptions also allow unrestricted access to ADP data for all seasons to date.

To subscribe to the API, sign into the Fantasy Football Analytics web app, click the “Subscribe” tab in the navigation bar, and use the select box to choose your subscription type. After you enter your credit card information and click the “Subscribe” button, the “Subscribe” modal will disappear. If you have successfully subscribed to the API, your API key will appear at the bottom of the “My Account” modal.

The API has two endpoints, “proj” and “adp”, which allow the user to get averaged projections and ADP data, respectively. API requests are expected to be made in the form of a simple HTTP GET, with users specifying various query parameters. Specifically, the optional query parameters for the “proj” endpoint are:

• pos: One of “qb” (default), “rb”, “wr”, “te”, “k”, “dst”, “dl”, “lb”, or “db”.
• season: A year between 2008 and the most recent NFL season (default), inclusive.
• week: An integer between 0 and 20, inclusive. The option week = 0 (default) corresponds to seasonal projections, whereas all other options correspond to weekly projections. The options week > 17 are used to designate playoff weeks. Weekly projections are not available for seasons prior to 2015.
• type: Scheme used to average individual projection sources; one of “average” (simple average; default), “robust” (robust average, which is resistant to outliers), or “weight” (weighted average, whereby the weights are based on historical projection accuracy).

The optional query parameters for the “adp” endpoint are:

• season: A year between 2015 and the most recent NFL season (default), inclusive.
• type: League type; either “std” (standard; default) or “ppr” (points-per-reception).

API calls can be made using a programming language of your choice. In particular, the example below demonstrates how to get weighted average projections for team defenses for the 2016 season using R. (Be sure to replace “YOUR_API_KEY” with your actual unique API key for the Authorization header.) Analogously, ADP data may be retrieved by changing the “endpoint” parameter to “adp” and setting the query parameters appropriately.

# query parameters
pos <- "dst"
season <- 2016
week <- 0
type <- "weight"

# construct API URL
protocol <- "http"
host <- "api.fantasyfootballanalytics.net/api"
endpoint <- "proj"
query.string <- paste0("?pos=", pos, "&season=", season, "&week=", week, "&type=", type)
URL <- paste0(protocol, "://", host, "/", endpoint, query.string)

# API key
api.key <- YOUR_API_KEY

# call API to get JSON
json <- httr::content(httr::GET(URL, httr::add_headers(Authorization = paste("Basic", api.key))),
type = "text")
# convert JSON to data frame
df <- jsonlite::fromJSON(json)

Please note that empty/null values are intentionally omitted from the returned JSON, following Google’s JSON style guide.

The post API Instructions appeared first on Fantasy Football Analytics.

To leave a comment for the author, please follow the link and comment on their blog: R – Fantasy Football Analytics.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)