API calls with R

Hi. I have a Dremio instance setup on Azure. Everything works fine. I can do API calls with Python and Postman, but for some reason I just cannot get it working with R. I really need to do this in R. I’m sure it is something very stupid that I’m doing wrong. The bit where I get the token works fine, but I cannot get the GET call working. Keep getting 401 error.

dremio_url <- “http://<dremio_instance>.northeurope.cloudapp.azure.com:9047”
dremio_uid <- “”
dremio_pwd <- “”
body <- paste0("{“userName”: “”, dremio_uid, “”, “password”: “”, dremio_pwd,""}")
path <- “apiv2/login”
verb <- “POST”
url <- httr::parse_url(dremio_url)
url$path <- URLencode(path)
headers <- list(“content-type” = ‘application/json’)
headers <- do.call(httr::add_headers, headers)
response <- httr::VERB(verb, url, headers, body = body)
token <- httr::content(response)$token

This token works if I use it in Postman

######################################################

This next section return’s a 401

headers <- list(“content-type” = ‘application/json’)
headers <- c(headers, Authorization=paste("_dremio", token, sep = “”, collapse = NULL))
headers <- do.call(httr::add_headers, headers)
verb <- “GET”
path <- “api/v3/catalog”
url <- httr::parse_url(dremio_url)
url$path <- URLencode(path)
response <- httr::VERB(verb, url, body = NULL, headers = headers)
response
#######################################

Thanks

@martindut, can you print the authorization token generated in the first step, use it in Postman, verify that it works, then hardcode this into the second section?

@ben, I did do that and all my calls work if I copy the body and token to Postman. I suspect R does some encoding which the Api doesn’t like. I managed to get it working with a mixture of R and Python, doing the Api calls in python. Thanks