I want to call the Companies House API from within R on a remote Linux server running Ubuntu 14.04 LTS. I am starting R from the terminal, and am using the 'httr' package and making the following GET request (using 'Paul+Dodd' as an example search term):
call <- GET("https://api.companieshouse.gov.uk/search/companies?q=Paul+Dodd&items_per_page=50&start_index=1", authenticate("API_KEY_HERE", ""))
You can apply for a Companies House API key and get more information on the API here: https://developer.companieshouse.gov.uk/api/docs/index.html
The response from the API call should be a complex list of company information.
However I am getting the following error:
Error in curl::curl_fetch_memory(url, handle = handle) : SSL connect error
I have tried set_config( config( ssl_verifypeer = 0L ) )
, which occasionally gives the correct response object but usually gives either the SSL error above or the following error:
Failure when receiving data from the peer
The above API call works when running R on my Windows desktop (running Windows 7) and on my mac. The API call works from multiple IP addresses.
I have installed the following dependencies on the remote server and have upgraded and updated but the error persists:
sudo apt-get upgrade
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libssl-dev
Finally, when I exit R and run the API call in the remote server's terminal I get the correct response. The command I used is as follows:
curl -u"API_KEY_HERE": https://api.companieshouse.gov.uk/search/companies?q=Paul+Dodd&items_per_page=50&start_index=1
I suspect the SSL connect error in R may be an issue with CA certificates, however I am at the limit of my knowledge of SSL. Do you have any suggestions as to how I might fix this so that I can call the API from within R using httr?
After some trial and error, I found that installing the following packages: jsonlite, mime, curl (≥ 0.9.1), openssl (≥ 0.8), R6 using:
install.packages("package_name")
solved the issue.