I am testing an internal FHIR api, to pull the data into R. This is a test environment with basic HTTP authentication. It works when I try with python http.client.HTTPSConnection . Also works with API tested online. I am not sure what I am missing when using the httr package in R. I get the following message "Authentication information not present or not in the correct format" .
Appreciate your help. I tried the RonFHIR r package and it does not work either.
It seems in Python, you don't configure an authentification.
With httr, if you only configure the header with the encoded authorization, do you have the same error ?
Tried that, this isn't working. I used httr package in r for other API's and it did work well. This FHIR api is something that is giving an issue. Not sure, why python was able to handle well, where I can get JSON data and unable to replicate in R. httr is literally reading the url, if I paste url in browser I do get "Authentication information not present..." May be something in establishing in connection seems to be different with python and httr or encoding ? I will try to dig more and see if I can find any specific issue.
For now, I am using reticulate package and pulling the JSON object back into R and working with it.
I get a new error now for the GET call, I am on windows.
Error in curl::curl_fetch_memory(url, handle = handle) :
Protocol "" not supported or disabled in libcurl
over SO, I found that the curl error is related to SSL certificate. Tried to ignore by the setting below
httr::set_config( config( ssl_verifypeer = 0L ) )
Its a test api and test data, so I shared the original keys on github. But, I understand it is not safe. Its probably too much to ask for, but as I see from your examples and based on the github examples I am passing it as expected by httr. If you would have time to try I can email you the keys.
In the header you posted above, you have content-type: application/json. This concerns what you send in the request as body. It is why you don't get a JSON returned. The keyword for that in header is Accept: application/json, to tell the API server that you accept only json in return.
This is exactly what accept_json() helper will add to your current request.
The equivalent of what you are doing currently is httr::content_type_json()
See the help page of those function for more details.