# Get Customers
customers_df <- recharge_get("/customers", query = list(limit = 250))$customers
# Get Subscriptions (paginated)
get_recharge_data <- function(endpoint, limit = 250) {
page <- 1
all_data <- list()
repeat {
cat("Fetching page:", page, "\n")
res <- GET(
url = paste0(base_url, "/", endpoint),
query = list(page = page, limit = limit),
add_headers("X-Recharge-Access-Token" = access_token)
)
if (status_code(res) != 200) {
print(content(res, "text", encoding = "UTF-8"))
stop("❌ Failed to retrieve data from Recharge.")
}
parsed <- content(res, "parsed", simplifyDataFrame = TRUE)
items <- parsed[[endpoint]]
if (length(items) == 0) break
all_data[[page]] <- items
page <- page + 1
}
return(dplyr::bind_rows(all_data))
}
subs_df <- get_recharge_data("subscriptions")