Quickstart
This guide will get you connected to the Jones Center Weather API from R in a few minutes. Authentication uses your existing @jonesctr.org account — no separate API key needed.
Prerequisites
- R 4.4 or higher
- Positron or RStudio
- A
@jonesctr.orgaccount with API access — contact it@jonesctr.org to request access
Install Required Packages
The script below will automatically install any missing packages on first run.
required_packages <- c("AzureAuth", "httr2", "httpuv", "dplyr")
missing_pkgs <- required_packages[!required_packages %in% rownames(installed.packages())]
if (length(missing_pkgs)) install.packages(missing_pkgs)
Full Script
Copy and run this in Positron or RStudio. The browser will open on first run — sign in with your @jonesctr.org account. The token is cached automatically so you only need to sign in once per session.
required_packages <- c("AzureAuth", "httr2", "httpuv", "dplyr")
missing_pkgs <- required_packages[!required_packages %in% rownames(installed.packages())]
if (length(missing_pkgs)) install.packages(missing_pkgs)
library(AzureAuth)
library(httpuv)
library(httr2)
library(dplyr)
# ---- Constants ---------------------------------------------------------------
TENANT_ID <- "d1f21831-a420-4b90-a1bd-be2d7f4025e1"
APP_ID <- "e3ab7f68-9182-412e-bcf3-760e6ba333bc"
RESOURCE_ID <- "e3ab7f68-9182-412e-bcf3-760e6ba333bc"
BASE_URL <- "https://api.jonesctr.org/weather/api"
# ---- Authentication ----------------------------------------------------------
# Opens a browser window; token is cached so this only prompts once per session.
token <- get_azure_token(
resource = RESOURCE_ID,
tenant = TENANT_ID,
app = APP_ID,
auth_type = "authorization_code"
)
# ---- Helper: fetch one page --------------------------------------------------
fetch_page <- function(endpoint, filter = NULL, top = 1000, after = NULL) {
request(paste0(BASE_URL, "/", endpoint)) |>
req_auth_bearer_token(token$credentials$access_token) |>
req_headers("X-MS-API-ROLE" = "WeatherAPI.Read") |>
req_url_query(
`$filter` = filter,
`$orderby` = "TmStamp desc",
`$first` = top,
`$after` = after
) |>
req_error(body = function(resp) resp_body_string(resp)) |>
req_perform() |>
resp_body_json(simplifyVector = TRUE)
}
# ---- Pull last 7 days --------------------------------------------------------
# 7 days x 24 hours x 4 readings/hour = 672 records
fifteen_min <- fetch_page("CraftonWS_FifteenMin", top = 672)$value
# 7 daily summaries
daily <- fetch_page("CraftonWS_Daily", top = 7)$value
glimpse(fifteen_min)
glimpse(daily)
Token Cache
AzureAuth caches your token automatically. On first use it will ask permission to create a cache directory — allow this. Future sessions will reuse the cached token without prompting you to sign in again.
If your token stops working or you need to sign in with a different account, clear the cache and re-authenticate:
library(AzureAuth)
clean_token_directory()
Then run the full script again.
Next Steps
- See the API Reference for all available endpoints and query parameters
- See the Data Dictionary for column definitions and units