15 lines
718 B
R
15 lines
718 B
R
getStationPaquet <- function(id_station, format = "csv", headers = headersPaquet) {
|
|
base_url <- modify_url(base, path = paste0(dpPaquetObs, "infrahoraire-6m"))
|
|
url_with_params <- modify_url(base_url, query = list(id_station = id_station, format = format))
|
|
|
|
response <- GET(url_with_params, add_headers(.headers = headers))
|
|
|
|
if (response$status_code == 200) {
|
|
# Successfully retrieved the data
|
|
return(read.csv(text = content(response, "text"), sep = ";", header = TRUE))
|
|
} else {
|
|
# If the request failed, it's useful to provide the status code in the error message for debugging
|
|
stop(sprintf("Failed to retrieve data as paquet from the API. Status code: %s", response$status_code))
|
|
}
|
|
}
|
|
|