inbo / iassetR

Interact with the iAsset api using R
https://inbo.github.io/iassetR/
Other
0 stars 1 forks source link

httr2 doesn't seem to work for get_records(), but httr does #3

Closed PietrH closed 9 months ago

PietrH commented 9 months ago

I'm used to writing my httr2 requests like this:

get_records <- function(inspection_name = "Vespa-Watch",
                        access_token = get_access_token(quiet = TRUE)) {
  # check input params
  assertthat::assert_that(assertthat::is.string(access_token))
  assertthat::assert_that(assertthat::is.string(inspection_name))
  # get the inspection_id for the custom inspection
  inspection_fields <- get_fields(access_token = access_token,
                                  name = inspection_name)
  # build a request and perform it
  get_records_request <-
    httr2::request("https://api.iasset.nl/getCustomInspections") %>%
    httr2::req_body_form(
      access_token = access_token,
      "inspection_ids[0]" = inspection_fields$id,
      version = "9.7"
    )
}

but it doesn't work, while this in httr does:


body = list(
  'access_token' = access_token,
  'version' = '9.7',
  'inspection_ids[0]' = inspection_fields$id
)

res <-
  httr::VERB(
    "POST",
    url = "https://api.iasset.nl/getCustomInspections",
    body = body,
    encode = 'multipart'
  )

# cat(content(res, 'text'))

res %>% httr::content()
PietrH commented 9 months ago

Strangely, my original code seems to work for me today, and rather quickly too. Under 5 seconds. Very strange. I'll keep this open for now