operational requests no longer working
oSamTo opened this issue · 1 comments
Hi, i am using the BMRSr package to query many things, I last used it a few months ago (June 2021?) however those same queries do not work, the principle error appears to be the time format but i am not sure;
(i'm using the development version devtools::install_github("ARawles/BMRSr")' )
full_request(data_item = "FUELINST",
api_key = my.bmrs.key,
from_datetime = "01 07 2019 00:00:00",
to_datetime = "03 07 2019 00:00:00",
service_type = "csv",
parse=T,
clean_dates = TRUE)
gives
$response
$response$responseMetadata
$response$responseMetadata$httpCode
$response$responseMetadata$httpCode[[1]]
[1] "400"
$response$responseMetadata$errorType
$response$responseMetadata$errorType[[1]]
[1] "Bad request"
$response$responseMetadata$description
$response$responseMetadata$description[[1]]
[1] "Either FromDateTime Parameter is not in proper format (yyyy-MM-dd HH:mm:ss) or is invalid"
$response$responseMetadata$queryString
$response$responseMetadata$queryString[[1]]
[1] "FromDateTime=2019-07-01%2000:00:00,ToDateTime=2019-07-03%2000:00:00"
Warning message:
csv requested, xml returned. Error code within response = 400
the only thing i have tried is to change the datetime to;
from_datetime = "2019-07-01 00:00:00",
to_datetime = "2019-07-03 00:00:00",
as per the API guide pdf, which gives exactly the same error message. Could be something at BMRS's end
Playing around by manually editing the string, I think I have worked out the problem. The API call seems to want the date time without any reformatting of the spaces or symbols i.e. 2019-07-03%2000:00:00"
https://api.bmreports.com/BMRS/FUELINST/v1?APIKey=YOUR_KEY&FromDateTime=2019-07-01 00:00:00&ToDateTime=2019-07-03 00:00:00&ServiceType=csv
The following code allowed me to pull the data
api_key <- # add yours
from_datetime <- "2019-07-01 00:00:00"
to_datetime <- "2019-07-03 00:00:00"
string <- glue::glue("https://api.bmreports.com/BMRS/FUELINST/v1?APIKey={api_key}&FromDateTime={from_datetime}&ToDateTime={to_datetime}&ServiceType=csv")
readr::read_csv(string)