Skip to content

Commit bbfe18b

Browse files
authored
Updated URLs for the read_api etc to point to the latest API endpoint… (#267)
* Updated URLs for the read_api etc to point to the latest API endpoint as updated by the ABS on 29 November 2024, api.data.abs.gov.au replaced by data.api.abs.gov.au with further structural changes to the API URL required * updated test url in test suite to match updates from ABS --------- Authored-by: Christian Klettner <[email protected]>
1 parent 46ce874 commit bbfe18b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

R/read_api.R

+10-10
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
#' try(read_api("ABS_C16_T10_SA", datakey = list(regiontype = "DZN")))
9797
#'
9898
#' # If you already have a query url, then use `read_api_url()`
99-
#' wpi_url <- "https://api.data.abs.gov.au/data/ABS,WPI/all"
99+
#' wpi_url <- "https://data.api.abs.gov.au/rest/data/ABS,WPI/all"
100100
#' read_api_url(wpi_url)
101101
#' }
102102
#' @name abs_api
@@ -106,7 +106,7 @@ NULL
106106
#' @rdname abs_api
107107
read_api_dataflows <- function() {
108108
check_abs_connection()
109-
r <- httr::GET(abs_api_url("dataflow/ABS"))
109+
r <- httr::GET(abs_api_url("rest/dataflow/ABS"))
110110
r <- httr::content(r)
111111
out <- purrr::map_dfr(r$references, ~ .[c("id", "name", "version")])
112112
names(out) <- c("id", "name", "version")
@@ -139,7 +139,8 @@ read_api <- function(id, datakey = NULL, start_period = NULL, end_period = NULL,
139139
} else {
140140
k <- "all"
141141
}
142-
url <- abs_api_url(c("data", dataflow, k), q)
142+
143+
url <- abs_api_url(c("rest", "data", dataflow, k), q)
143144

144145
# Fetch data
145146
df <- abs_api_fetch_data(url)
@@ -167,7 +168,7 @@ read_api_url <- function(url) {
167168
read_api_datastructure <- function(id) {
168169
check_abs_connection()
169170

170-
r <- httr::GET(abs_api_url(c("datastructure", "ABS", id, "?references=codelist")), httr::accept_xml())
171+
r <- httr::GET(abs_api_url(c("rest", "dataflow", "ABS", id, "?references=all")), httr::accept_xml())
171172
httr::stop_for_status(r)
172173
r <- httr::content(r)
173174

@@ -220,7 +221,7 @@ read_api_datastructure <- function(id) {
220221
#'
221222
#' abs_api_url(c("a", "path"), query = c(nulls = NULL, get = "dropped"))
222223
abs_api_url <- function(path, query = NULL) {
223-
out <- paste0("https://api.data.abs.gov.au/", paste(path, collapse = "/"))
224+
out <- paste0("https://data.api.abs.gov.au/", paste(path, collapse = "/"))
224225
if (!is.null(query)) {
225226
query <- paste(names(query), query, sep = "=")
226227
out <- paste0(out, "?", paste(query, collapse = "&"))
@@ -229,7 +230,6 @@ abs_api_url <- function(path, query = NULL) {
229230
out
230231
}
231232

232-
233233
#' Extract dataflow id from url string
234234
#'
235235
#' @param url A url string
@@ -240,13 +240,13 @@ abs_api_url <- function(path, query = NULL) {
240240
#'
241241
abs_api_id_from_url <- function(url) {
242242
stopifnot("`url` must be of length 1" = length(url) == 1)
243-
if (!grepl("^https://api.data.abs.gov.au/data/ABS,", url)) {
243+
if (!grepl("^https://data.api.abs.gov.au/rest/data/ABS,", url)) {
244244
stop("`url` is not an ABS query url. Query urls must match regex: \n\t",
245-
"'^https://api.data.abs.gov.au/data/ABS,.*'",
246-
call. = FALSE
245+
"'^https://data.api.abs.gov.au/rest/data/ABS,.*'",
246+
call. = FALSE
247247
)
248248
}
249-
id <- strsplit(url, "/")[[1]][5]
249+
id <- strsplit(url, "/")[[1]][6]
250250
id <- strsplit(id, ",")[[1]][2]
251251
id
252252
}

tests/testthat/test-abs_api.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test_that("url queries work", {
5555
skip_on_cran()
5656
check_abs_connection()
5757

58-
wpi_url <- "https://api.data.abs.gov.au/data/ABS,WPI/all"
58+
wpi_url <- "https://data.api.abs.gov.au/rest/data/ABS,WPI/all"
5959
res <- read_api_url(wpi_url) %>%
6060
arrange(measure, index, sector, industry, tsest, region, freq, time_period)
6161

0 commit comments

Comments
 (0)